Insure++ Reference - ALLOC_CONFLICT
This error is generated when a memory block is allocated with
new(malloc) and freed with
free(delete) .
Insure++ distinguishes between the two possibilities as follows:
badfree
|
Memory was allocated with new or
new[] and an attempt was
made to free it with free .
|
baddelete
|
Memory was allocated with malloc and an attempt was
made to free it with delete or delete[]
.
|
Some compilers do allow this, but it is not good programming practice
and could be a portability problem.
The following code shows a typical example of allocating a block of
memory with new and then freeing it with
free , instead of delete .
1: /*
2: * File: alloc1.C
3: */
4: #include <stdlib.h>
5:
6: int main() {
7: char *a;
8:
9: a = new char;
10: free(a);
11: return 0;
12: }
1. [alloc1.C:10] **ALLOC_CONFLICT**
>> free(a);
2. Memory allocation conflict: a
3. free() used to deallocate memory which was allocated
using new
a, allocated at:
main() alloc1.C, 9
4. Stack trace where the error occurred:
main() alloc1.C, 10
- Source line at which the problem was detected.
- Brief description of the problem.
- Description of the conflicting allocation/deallocation.
- Stack trace showing the function call sequence leading to the error.
The following code shows another typical example of this type of
error, allocating a block of memory with malloc
and then freeing it with delete .
1: /*
2: * File: alloc2.C
3: */
4: #include <stdlib.h>
5:
6: int main() {
7: char *a;
8:
9: a = (char *) malloc(1);
10: delete a;
11: return 0;
12: }
1. [alloc2.C:10] **ALLOC_CONFLICT**
>> delete a;
2. Memory allocation conflict: a
3. delete operator used to deallocate memory not
allocated by new
block allocated at:
malloc() (interface)
main() alloc2.C, 9
4. Stack trace where the error occurred:
main() alloc2.C, 10
- Source line at which the problem was detected.
- Brief description of the problem.
- Description of the conflicting allocation/deallocation.
- Stack trace showing the function call sequence leading to the error.
This type of error can be corrected by making sure that all your
memory allocations match up.
Error Codes
BAD_CAST
|