I allocate memory in a C program using malloc . Perhaps my program allocates more memory than the system has space, and at that moment the program will fail. For my purposes, it would be better if malloc just returned NULL (as if it should ), so I can catch the error. Instead, it displays the error message "There is no memory for programming now: it is not safe to call malloc." And the program crashes.
How can i fix this?
Edit: I know that a program crashes on its own, and not because I'm trying to reference a null pointer. A program never directly calls malloc , but instead calls a function that I wrote, which calls malloc , and then checks to see if it returns NULL . He never said that malloc returned NULL .
Edit 2: if this is useful, here is the complete error output:
Programmed signal: "EXC_BAD_ACCESS".
sharedlibrary apply-load-rules all
warning: it is not possible to restore a previously selected frame.
Data formats are temporarily unavailable, try again after continuing. (The program to be debugged was specified in a function called by GDB.
GDB remains in the frame where the signal was received.
To change this behavior, use "set unwindonsignal on"
The evaluation of the expression containing the function (dlopen) will be terminated.)
Now there is no memory for programming: it is not safe to call malloc
source share