/ Published in: C
In C, you have to manage your own program's memory. So if you allocate memory using malloc() you should not forget to free() it when no longer required.
You should also make sure if there is available memory in your system to allocate.
You should also make sure if there is available memory in your system to allocate.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Add this function: #include <stdlib.h> #define MALLOC_ERROR -1 ... static void *checked_malloc(const size_t size) { void *data; if (data == NULL) { } return data; } Then, invoke the method with: char *new_data; size_t whatever_u_need = 20; new_data = checked_malloc(whatever_u_need);