Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Malloc Check Failed: lib/c/alloc/dlist.c:748: (3 Items)
   
Malloc Check Failed: lib/c/alloc/dlist.c:748  
We are allocating memory as follows in our CPP application:

            ptr = new T[numElements];   
           if(ptr == NULL)
              //assert. 

Where T is a typename template, numElements is > 0 and also NULL check for ptr after allocation is properly handled.

Deallocation:
            if(ptr != NULL)
            {
                delete[] ptr;
                ptr = NULL;
            } 

We have a structure with more than 15 members of different types. During allocation total of 10793022 bytes were 
allocated. When de-allocating the members one by one in the same order which were allocated, our application is crashing
 with the below error:
Malloc Check Failed: :/builds/workspace/QOS221-SDP/build_aarch64/lib/c/alloc/dlist.c:748
Abort (core dumped)

Core dump is not useful. 

Double-checked that we are not deallocating any memory that is not allocated and also the ptr also valid The same 
application working without any issues in Windows platform as well as another Embedded platform. Only in QNX its 
crashing. We would like to know exactly in which scenarios "Malloc check Failed" message will be thrown by dlist.c. It 
would be more helpful if you share this information, so that we could check the possible causes in our application. 

Please let me know if any other additional information is needed,
Re: Malloc Check Failed: lib/c/alloc/dlist.c:748  
The most likely explanation is that somewhere in your code you are writing outside the bounds of the array (or some 
other way in which the heap meta-data gets overwritten). The QNX heap code checks for such corruption, other systems may
 not.

The best way to find out what is going on is to use a memory analysis tool such as Valgrind.

--Elad
Re: Malloc Check Failed: lib/c/alloc/dlist.c:748  
Thank you Elad.

Hardware(QDrive): QualCOMM Snapdragon ride platform
QNX: SDK 11.1

Is it possible to run valgrind without using Momentics IDE? Basically our application is crashing in initialization 
itself if we run through Momentics[We are talking to the appropriate team to fix this. Even simple programs is not 
working]. So for now, What we basically do is copy our executable to the QDrive through WinSCP and execute through 
command prompt using telnet to that QDrive IP. We've QNX SDK 11.1 on our QDrive. If we enter valgrind command, its not 
able to find.

# valgrind
sh: valgrind: cannot execute - No such file or directory

What is the correct way of using Valgrind tool  without using Momentics IDE? Do we need to re-build QNX SDK with certain
 option when configure/build to include valgrind? If so, Can you please specify. 

We download QNX SDK from https://chipcode.qti.qualcomm.com/
Currently using sa8540p-qx-1-0_hlos_dev_qnx/tree/r00011.1a.502856.3 SDK.

Note:
Please let me know if it is not the right  forum to ask questions about valgrind and point me to the appropriate forum.