Skip to content

Commit 3a95e36

Browse files
authored
Update error-alloc-dealloc-mismatch.md
The original intent was correct--if hard to parse. Hopefully this makes it clearer.
1 parent 83032f4 commit 3a95e36

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/sanitizers/error-alloc-dealloc-mismatch.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
---
22
title: "Error: alloc-dealloc-mismatch"
3-
description: "Source examples and live debug screenshots for alloc-dealloc-mismatch errors."
4-
ms.date: 03/02/2021
3+
description: "Learn about the alloc-dealloc-mismatch Address Sanitizer error."
4+
ms.date: 05/28/2025
55
f1_keywords: ["alloc-dealloc-mismatch"]
66
helpviewer_keywords: ["alloc-dealloc-mismatch error", "AddressSanitizer error alloc-dealloc-mismatch"]
77
---
88
# Error: `alloc-dealloc-mismatch`
99

1010
> Address Sanitizer Error: Mismatch between allocation and deallocation APIs
1111
12-
The `alloc`/`dealloc` mismatch functionality in AddressSanitizer is off by default for Windows. To enable it, run `set ASAN_OPTIONS=alloc_dealloc_mismatch=1` before running the program. This environment variable is checked at runtime to report errors on `malloc`/`free`, `new`/`delete`, and `new[]`/`delete[]`.
12+
Enables runtime detection of mismatched memory operations that may lead to undefined behavior, such as:
13+
`malloc` paired with `delete` (use `free` to release memory allocated with `malloc`)
14+
`new` paired with `free` (use `delete` to release memory allocated with `new`)
15+
`new` paired with `delete[]`, (use `delete[]` only when releasing an array allocated with `new` ) and so on.
16+
17+
The `alloc`/`dealloc` mismatch functionality in AddressSanitizer is off by default for Windows. To enable it, run `set ASAN_OPTIONS=alloc_dealloc_mismatch=1` before running the program.
1318

1419
## Example
1520

1621
```cpp
17-
// example1.cpp
1822
// alloc-dealloc-mismatch error
1923
#include <stdio.h>
2024
#include <stdlib.h>
@@ -40,7 +44,7 @@ int main(int argc, char* argv[]) {
4044
}
4145
```
4246
43-
To build and test this example, run these commands in a Visual Studio 2019 version 16.9 or later [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts):
47+
To try this example, run the following commands in a Visual Studio 2019 version 16.9 or later [developer command prompt](../build/building-on-the-command-line.md#developer_command_prompt_shortcuts):
4448
4549
```cmd
4650
cl example1.cpp /fsanitize=address /Zi

0 commit comments

Comments
 (0)