You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> 'realloc' may return null pointer: assigning a null pointer to '\**parameter-name*', which is passed as an argument to 'realloc', will cause the original memory block to be leaked
15
13
16
-
## Description
14
+
## Remarks
17
15
18
-
This warning indicates a memory leak due to the unsafe use of a reallocation function. Heap reallocation functions don't free the passed buffer if reallocation is unsuccessful. To correct the issue, assign the result of the reallocation function to a temporary location, and then replace the original pointer after successful reallocation.
16
+
Heap reallocation functions don't free the passed buffer if reallocation is unsuccessful, potentially resulting in a memory leak if not handled properly. To correct the issue, assign the result of the reallocation function to a temporary location, and then replace the original pointer after successful reallocation.
17
+
18
+
Code analysis name: REALLOCLEAK
19
19
20
20
## Example
21
21
@@ -27,14 +27,14 @@ The following sample code generates this warning. This issue stems from the assi
27
27
28
28
voidf( )
29
29
{
30
-
char *x;
31
-
x = (char *) malloc(10);
32
-
if (x != NULL)
33
-
{
34
-
x = (char *) realloc(x, 512);
35
-
// code...
36
-
free(x);
37
-
}
30
+
char *x;
31
+
x = (char *) malloc(10);
32
+
if (x != NULL)
33
+
{
34
+
x = (char *) realloc(x, 512);
35
+
// code...
36
+
free(x);
37
+
}
38
38
}
39
39
```
40
40
@@ -46,18 +46,18 @@ To resolve the issue, you can create a temporary variable to store the return st
0 commit comments