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
Copy file name to clipboardExpand all lines: docs/sanitizers/error-alloc-dealloc-mismatch.md
+16-17Lines changed: 16 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,40 +19,39 @@ The `alloc`/`dealloc` mismatch functionality in AddressSanitizer is off by defau
19
19
## Example
20
20
21
21
```cpp
22
-
// alloc-dealloc-mismatch error
22
+
//Demonstrate alloc-dealloc-mismatch error
23
23
#include<stdio.h>
24
24
#include<stdlib.h>
25
25
26
-
intmain(int argc, char* argv[]) {
27
-
26
+
intmain(int argc, char* argv[])
27
+
{
28
28
if (argc != 2) return -1;
29
29
30
-
switch (atoi(argv[1])) {
31
-
32
-
case 1:
33
-
delete[](new int[10]);
34
-
break;
35
-
case 2:
36
-
delete (new int[10]); // Boom!
37
-
break;
38
-
default:
39
-
printf("arguments: 1: no error 2: runtime error\n");
40
-
return -1;
30
+
switch (atoi(argv[1]))
31
+
{
32
+
case 1:
33
+
delete[](new int[10]);
34
+
break;
35
+
case 2:
36
+
delete (new int[10]); // Boom!
37
+
break;
38
+
default:
39
+
printf("arguments: 1: no error 2: runtime error\n");
40
+
return -1;
41
41
}
42
-
43
42
return 0;
44
43
}
45
44
```
46
45
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):
46
+
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) to run the example:
48
47
49
48
```cmd
50
49
cl example1.cpp /fsanitize=address /Zi
51
50
set ASAN_OPTIONS=alloc_dealloc_mismatch=1
52
51
devenv /debugexe example1.exe 2
53
52
```
54
53
55
-
### Resulting error
54
+
### Output
56
55
57
56
:::image type="content" source="media/alloc-dealloc-mismatch-example-1.png" alt-text="Screenshot of debugger displaying alloc-dealloc-mismatch error in example 1.":::
0 commit comments