]>
Commit | Line | Data |
---|---|---|
cdc6e186 | 1 | Index: src/audits/memman.cpp |
2 | =================================================================== | |
3 | --- src/audits/memman.cpp (revision 223) | |
4 | +++ src/audits/memman.cpp (working copy) | |
5 | @@ -114,13 +114,22 @@ | |
6 | return; | |
7 | } | |
8 | ||
9 | - pointer_map.erase(p); | |
10 | + | |
11 | bool array_mismatch = (is_array != i->second.is_array); | |
12 | - mtx_memman.unlock(); | |
13 | ||
14 | // Check mixing of array new/delete | |
15 | + // NOTE: after the pointer has been erased from pointer_map, the | |
16 | + // iterator i is invalid. | |
17 | + // The mutex mtx_memman should be unlocked before logging to | |
18 | + // avoid dead locks. | |
19 | if (array_mismatch) { | |
20 | num_array_mixing++; | |
21 | + string allocation_filename = i->second.filename; | |
22 | + int allocation_lineno = i->second.lineno; | |
23 | + bool allocation_is_array = i->second.is_array; | |
24 | + pointer_map.erase(p); | |
25 | + mtx_memman.unlock(); | |
26 | + | |
27 | log_file->write_header("t_memman::trc_delete", | |
28 | LOG_MEMORY, LOG_WARNING); | |
29 | log_file->write_raw(filename); | |
30 | @@ -130,21 +139,24 @@ | |
31 | log_file->write_raw(ptr2str(p)); | |
32 | log_file->write_raw(" is deleted "); | |
33 | if (is_array) { | |
34 | - log_file->write_raw(" as array (delete []).\n"); | |
35 | + log_file->write_raw("as array (delete []).\n"); | |
36 | } else { | |
37 | - log_file->write_raw(" normally (delete).\n"); | |
38 | + log_file->write_raw("normally (delete).\n"); | |
39 | } | |
40 | log_file->write_raw("But it was allocated "); | |
41 | - if (i->second.is_array) { | |
42 | - log_file->write_raw(" as array (new []) \n"); | |
43 | + if (allocation_is_array) { | |
44 | + log_file->write_raw("as array (new []) \n"); | |
45 | } else { | |
46 | - log_file->write_raw(" normally (new) \n"); | |
47 | + log_file->write_raw("normally (new) \n"); | |
48 | } | |
49 | - log_file->write_raw(i->second.filename); | |
50 | + log_file->write_raw(allocation_filename); | |
51 | log_file->write_raw(", line "); | |
52 | - log_file->write_raw(i->second.lineno); | |
53 | + log_file->write_raw(allocation_lineno); | |
54 | log_file->write_endl(); | |
55 | log_file->write_footer(); | |
56 | + } else { | |
57 | + pointer_map.erase(p); | |
58 | + mtx_memman.unlock(); | |
59 | } | |
60 | } | |
61 |