This page was produced by an automated import process, and may have formatting errors; feel free to fix.

Memory Management

GDB does not use the functions malloc, realloc, calloc, free and asprintf.

GDB uses the functions xmalloc, xrealloc and xcalloc when allocating memory. Unlike malloc et.al. these functions do not return when the memory pool is empty. Instead, they unwind the stack using cleanups. These functions return NULL when requested to allocate a chunk of memory of size zero.

Pragmatics: By using these functions, the need to check every memory allocation is removed. These functions provide portable behavior.

GDB does not use the function free.

GDB uses the function xfree to return memory to the memory pool. Consistent with ISO-C, this function ignores a request to free a NULL pointer.

Pragmatics: On some systems free fails when passed a NULL pointer.

GDB can use the non-portable function alloca for the allocation of small temporary values (such as strings).

Pragmatics: This function is very non-portable. Some systems restrict the memory being allocated to no more than a few kilobytes.

GDB uses the string function xstrdup and the print function xstrprintf.

Pragmatics: asprintf and strdup can fail. Print functions such as sprintf are very prone to buffer overflow errors.

None: Internals Memory-Management (last edited 2013-08-20 23:41:00 by StanShebs)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.