Skip to content

Commit bfb00d4

Browse files
authored
Merge pull request #3098 from JordanMaples/patch-11
Add example and Core Guidelines link to C26408
2 parents f18870f + bb600f5 commit bfb00d4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/code-quality/c26408.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ms.topic: "conceptual"
55
f1_keywords: ["C26408"]
66
helpviewer_keywords: ["C26408"]
77
ms.assetid: 55b0706f-1107-41c1-8ad0-c9e1e86a3b8c
8+
description: CppCoreCheck rule that enforces C++ Core Guidelines R.10
89
---
910
# C26408 NO_MALLOC_FREE
1011

@@ -15,3 +16,23 @@ This warning flags places where `malloc` or `free` is invoked explicitly in acco
1516
- To detect malloc() we check if a call invokes a global function with name "malloc" or "std::malloc". The function must return a pointer to **`void`** and accept one parameter of unsigned integral type.
1617

1718
- To detect free() we check global functions with names "free" or "std::free" which return no result and accept one parameter, which is a pointer to **`void`**.
19+
20+
## See also
21+
[C++ Core Guidelines R.10](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r10-avoid-malloc-and-free)
22+
23+
## Example
24+
```cpp
25+
#include <new>
26+
27+
struct myStruct {};
28+
29+
void function_malloc_free() {
30+
myStruct* ms = static_cast<myStruct*>(malloc(sizeof(myStruct))); // C26408
31+
free(ms); // C26408
32+
}
33+
34+
void function_nothrow_new_delete() {
35+
myStruct* ms = new(std::nothrow) myStruct;
36+
operator delete (ms, std::nothrow);
37+
}
38+
```

0 commit comments

Comments
 (0)