Skip to content

Commit 6dfe664

Browse files
Updated C6308
Updated to the new format, spacing made consistent with my other PRs
1 parent 6dc566c commit 6dfe664

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

docs/code-quality/c6308.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
22
title: C6308
33
description: "Understand the causes of Microsoft C/C++ code analysis warning C6308, and learn how to fix them."
4-
ms.date: 10/23/2020
4+
ms.date: 08/18/2022
55
ms.topic: reference
6-
f1_keywords: ["C6308"]
6+
f1_keywords: ["C6308", "REALLOCLEAK", "__WARNING_REALLOCLEAK"]
77
helpviewer_keywords: ["C6308"]
88
ms.assetid: 1162cd96-9037-4576-9858-0c8361a12559
99
---
10-
# C6308
10+
# Warning C6308
1111

12-
**Warning C6308: Memory Reallocation Leak (REALLOCLEAK)**\
13-
Example output:
1412
> '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
1513
16-
## Description
14+
## Remarks
1715

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
1919

2020
## Example
2121

@@ -27,14 +27,14 @@ The following sample code generates this warning. This issue stems from the assi
2727

2828
void f( )
2929
{
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+
}
3838
}
3939
```
4040
@@ -46,18 +46,18 @@ To resolve the issue, you can create a temporary variable to store the return st
4646
4747
void f()
4848
{
49-
char *x, *tmp;
50-
x = (char *) malloc(10);
51-
if (x != NULL)
52-
{
53-
tmp = (char *) realloc(x,512);
54-
if (tmp != NULL)
49+
char *x, *tmp;
50+
x = (char *) malloc(10);
51+
if (x != NULL)
5552
{
56-
x = tmp;
53+
tmp = (char *) realloc(x,512);
54+
if (tmp != NULL)
55+
{
56+
x = tmp;
57+
}
58+
// code...
59+
free(x);
5760
}
58-
// code...
59-
free(x);
60-
}
6161
}
6262
```
6363

0 commit comments

Comments
 (0)