Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Error with dynamic memory allocation operator "free()"

microvish
Beginner
325 Views
Hello All,
The compilation of my program is fine. But, when executing it, I get the following error exactly where I use "free()" to free up a dynamically allocated arraywith "malloc()". If I comment out the line containing "free()", the my program runs fine. Its the same error If I use "new" and "delete"

*** glibc detected *** WearProcessor.x: free(): invalid next size (normal): 0x00000000006661b0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x2adaf65d48fe]
/lib64/libc.so.6(cfree+0x76)[0x2adaf65d5f36]
WearProcessor.x[0x412bf4]
WearProcessor.x[0x402abd]
WearProcessor.x(__gxx_personality_v0+0x24b)[0x4021cb]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x2adaf6585ae4]
WearProcessor.x(__gxx_personality_v0+0x69)[0x401fe9]
======= Memory map: ========
00400000-00455000 r-xp 00000000 08:02 289759 /home/wpvh/Programming/3DPODFM-TM/WearProcessor.x
00654000-00655000 r-xp 00054000 08:02 289759 /home/wpvh/Programming/3DPODFM-TM/WearProcessor.x
00655000-00658000 rwxp 00055000 08:02 289759 /home/wpvh/Programming/3DPODFM-TM/WearProcessor.x
00658000-006f1000 rwxp 00658000 00:00 0 [heap]
2adaf5ae6000-2adaf5b02000 r-xp 00000000 08:02 25124 /lib64/ld-2.5.so
2adaf5b02000-2adaf5b39000 rwxp 2adaf5b02000 00:00 0
2adaf5b45000-2adaf5bab000 rwxp 2adaf5b45000 00:00 0
2adaf5d02000-2adaf5d04000 rwxp 0001c000 08:02 25124 /lib64/ld-2.5.so
2adaf5d04000-2adaf5d59000 r-xp 00000000 08:02 25139 /lib64/libm-2.5.so
2adaf5d59000-2adaf5f58000 ---p 00055000 08:02 25139 /lib64/libm-2.5.so
2adaf5f58000-2adaf5f5a000 rwxp 00054000 08:02 25139 /lib64/libm-2.5.so
2adaf5f5a000-2adaf603d000 r-xp 00000000 08:02 34492 /usr/lib64/libstdc++.so.6.0.8
2adaf603d000-2adaf623d000 ---p 000e3000 08:02 34492 /usr/lib64/libstdc++.so.6.0.8
2adaf623d000-2adaf6243000 r-xp 000e3000 08:02 34492 /usr/lib64/libstdc++.so.6.0.8
2adaf6243000-2adaf6246000 rwxp 000e9000 08:02 34492 /usr/lib64/libstdc++.so.6.0.8
2adaf6246000-2adaf6258000 rwxp 2adaf6246000 00:00 0
2adaf6258000-2adaf6265000 r-xp 00000000 08:02 33138 /lib64/libgcc_s.so.1
2adaf6265000-2adaf6464000 ---p 0000d000 08:02 33138 /lib64/libgcc_s.so.1
2adaf6464000-2adaf6466000 rwxp 0000c000 08:02 33138 /lib64/libgcc_s.so.1
2adaf6466000-2adaf6467000 rwxp 2adaf6466000 00:00 0
2adaf6467000-2adaf6468000 r-xp 00000000 08:02 422665 /opt/intel/fce/9.1.040/lib/libcxaguard.so.5
2adaf6468000-2adaf6567000 ---p 00001000 08:02 422665 /opt/intel/fce/9.1.040/lib/libcxaguard.so.5
2adaf6567000-2adaf6568000 rwxp 00000000 08:02 422665 /opt/intel/fce/9.1.040/lib/libcxaguard.so.5
2adaf6568000-2adaf66a1000 r-xp 00000000 08:02 25131 /lib64/libc-2.5.so
2adaf66a1000-2adaf68a0000 ---p 00139000 08:02 25131 /lib64/libc-2.5.so
2adaf68a0000-2adaf68a3000 r-xp 00138000 08:02 25131 /lib64/libc-2.5.so
2adaf68a3000-2adaf68a5000 rwxp 0013b000 08:02 25131 / lib64/libc-2.5.so
2adaf68a5000-2adaf68aa000 rwxp 2adaf68a5000 00:00 0
2adaf68aa000-2adaf68ac000 r-xp 00000000 08:02 25137 /lib64/libdl-2.5.so
2adaf68ac000-2adaf6aac000 ---p 00002000 08:02 25137 /lib64/libdl-2.5.so
2adaf6aac000-2adaf6aae000 rwxp 00002000 08:02 25137 /lib64/libdl-2.5.so
2adaf6aae000-2adaf6ab0000 rwxp 2adaf6aae000 00:00 0
2adaf8000000-2adaf8021000 rwxp 2adaf8000000 00:00 0
2adaf8021000-2adafc000000 ---p 2adaf8021000 00:00 0
7fffb4fad000-7fffb4fc4000 rwxp 7fffb4fad000 00:00 0 [stack]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0 [vdso]
Aborted


Please help me fix this error.

Best Regards,
microvish
0 Kudos
2 Replies
JenniferJ
Moderator
325 Views

What is the icc version, os version (kernel, glibc, gcc)? Make sure the compiler supports the os.

You may need to submit an issue report to PremierSupport https://premier.intel.com/. malloc/free are used very often, it doesn't seem a simple problem. It might be related to your specific case.

Jennifer

0 Kudos
jimdempseyatthecove
Honored Contributor III
325 Views

Microvish,

malloc, free (new, delete) will produce errors when your application modifies memory it does not own. Buffer overruns, indexing past end of array, de-referencing a pointer to freed memory are some of the programming errors that cause this problem. Debugger options can be used to find some of these errors but not all of these errors. Check MSDN under "heap corruption" this should give you some guidance. MSDN is available on Microsoft.com if you do not have a copy of it locally.

Finding the problem can be difficult because as you add diagnostic code, the memory layout changes and the problem may cease to produce symptoms i.e. trash data elsewhere but not abort the program. If you do not find the problem and if the problem (Aborting of program) goes away... You didnot fix the problem - the program still has a bug.

Jim Dempsey

0 Kudos
Reply