Top "Malloc" questions

The malloc function performs dynamic memory allocation in C and is part of the standard library.

ASAN heap use after free

I am running ASAN for finding memory leaks in a very big project. I have found out the cause, but …

c malloc heap free address-sanitizer
Can memset() be called with a null pointer if the size is 0?

For one reason or another, I want to hand-roll a zeroing version of malloc(). To minimize algorithmic complexity, I want …

c malloc memset
free() function without malloc or calloc

quick question Can you use the free() function without having to prior call a malloc ?? ei. void someFunc( void ) { char …

c malloc calloc
Copying n chars with strncpy more efficiently in C

I'm wondering if there's a cleaner and more efficient way of doing the following strncpy considering a max amount of …

c string malloc strncpy
using glibc malloc hooks in a thread safe manner

I would like to monitor the use of mallocs and frees in an application by using the malloc and free …

c malloc glibc
what does "malloc_trim(0)" really mean?

The manual page told me so much and through it I know lots of the background knowledge of memory management …

malloc glibc trim sbrk
Calling free on a pointer twice

I have been taught in lectures, that calling free() on a pointer twice is really, really bad. I know that …

c pointers malloc free dynamic-memory-allocation
Why does C++ require a cast for malloc() but C doesn't?

I have always been curious about this - why do in C++ I have to cast return value from malloc …

c++ c malloc
calloc -- Usefulness of zeroing out memory

What is the advantage of zeroing out memory (i.e. calloc() over malloc())? Won't you change the value to something …

c memory memory-management malloc calloc
does exit() free allocated memory on both _SUCCESS and _FAILURE

This a short snippet of code, with two calls to exit(3) in case of failure. Do these calls deallocate memory …

c malloc free exit