Skip to content

Commit f3f62ce

Browse files
authored
Give library functions code style
Fix date. Also tweak a sentence for readability.
1 parent 1a0d05e commit f3f62ce

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/code-quality/c6308.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: C6308
2+
title: Warning C6308
33
description: "Understand the causes of Microsoft C/C++ code analysis warning C6308, and learn how to fix them."
4-
ms.date: 08/18/2022
4+
ms.date: 09/28/2022
55
ms.topic: reference
66
f1_keywords: ["C6308", "REALLOCLEAK", "__WARNING_REALLOCLEAK"]
77
helpviewer_keywords: ["C6308"]
@@ -13,13 +13,13 @@ ms.assetid: 1162cd96-9037-4576-9858-0c8361a12559
1313
1414
## Remarks
1515

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.
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 variable, and then replace the original pointer after successful reallocation.
1717

1818
Code analysis name: REALLOCLEAK
1919

2020
## Example
2121

22-
The following sample code generates this warning. This issue stems from the assignment of `x` to the return value from realloc. If realloc fails and returns a NULL pointer, then `x` will fail to be freed:
22+
The following sample code generates warning C6308. This issue stems from the assignment of the return value from `realloc` to `x`. If `realloc` fails and returns a null pointer, then the original memory pointed to by `x` won't be freed:
2323

2424
```cpp
2525
#include <malloc.h>
@@ -37,7 +37,7 @@ void f( )
3737
}
3838
```
3939
40-
To resolve the issue, you can create a temporary variable to store the return status of realloc. This change allows you to free the previously allocated memory safely if realloc fails:
40+
To resolve the issue, you can create a temporary variable to store the return value of `realloc`. This change allows you to free the previously allocated memory safely if `realloc` fails:
4141
4242
```cpp
4343
#include <malloc.h>
@@ -61,8 +61,8 @@ void f()
6161

6262
This warning might generate noise if there's a live alias to the buffer-to-be-reallocated at the time of the assignment of the result of the reallocation function.
6363

64-
To avoid these kinds of issues altogether, you can use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [shared_ptr](../standard-library/shared-ptr-class.md), [unique_ptr](../standard-library/unique-ptr-class.md), and [vector](../standard-library/vector.md). For more information, see [Smart Pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
64+
To avoid these kinds of issues altogether, you can use the mechanisms that are provided by the C++ Standard Template Library (STL). These include [`shared_ptr`](../standard-library/shared-ptr-class.md), [`unique_ptr`](../standard-library/unique-ptr-class.md), and [`vector`](../standard-library/vector.md). For more information, see [Smart pointers](../cpp/smart-pointers-modern-cpp.md) and [C++ Standard Library](../standard-library/cpp-standard-library-reference.md).
6565

6666
## See also
6767

68-
[C6014](../code-quality/c6014.md)
68+
[Warning C6014](../code-quality/c6014.md)

0 commit comments

Comments
 (0)