pcb 4.1.1
An interactive printed circuit board layout editor.

free_atexit.c File Reference

More...

#include <stdlib.h>
#include <string.h>
Include dependency graph for free_atexit.c:

Go to the source code of this file.

Data Structures

union  leaky_admin_t
  More...

Typedefs

typedef unsigned int leaky_idx_t
 We need one ID per context - short int with 64k IDs should be enough.

Functions

void * leaky_malloc (size_t size)
 Allocate memory, remember the pointer and free it after exit from the application.
void * leaky_calloc (size_t nmemb, size_t size)
 Same as leaky_malloc but this one wraps calloc().
void * leaky_realloc (void *old_memory, size_t size)
 Reallocate memory, remember the new pointer and free it after exit from the application.
char * leaky_strdup (const char *src)
 strdup() using leaky_malloc().
void leaky_uninit (void)
 Free all allocations.
void leaky_init (void)
 Set up atexit() hook.

Variables

static void ** free_list = NULL
static leaky_idx_t free_size = 0

Detailed Description


Copyright.


Copyright (C) 2010 PCB Contributors (see ChangeLog for details)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Contact addresses for paper mail and Email: harry eaton, 6697 Buttonhole Ct, Columbia, MD 21044 USA haceaton@aplcomm.jhuapl.edu

This tiny library is to assist cleaning up harmless memory leaks caused by (growing) buffers allocated in static variables in functions.
The library provides leaky_ prefixed variants of the common allocation routines.
These wrappers will remember all pointers they return and can free all memory used, at the end of the application.

Definition in file free_atexit.c.


Typedef Documentation

typedef unsigned int leaky_idx_t

We need one ID per context - short int with 64k IDs should be enough.

Definition at line 38 of file free_atexit.c.


Function Documentation

void* leaky_calloc ( size_t  nmemb,
size_t  size 
)

Same as leaky_malloc but this one wraps calloc().

Definition at line 81 of file free_atexit.c.

References leaky_malloc().

Here is the call graph for this function:

void leaky_init ( void  )

Set up atexit() hook.

Can be avoided if leaky_uninit() is called by hand.

Definition at line 143 of file free_atexit.c.

References leaky_uninit().

Referenced by main().

Here is the call graph for this function:

void* leaky_malloc ( size_t  size)

Allocate memory, remember the pointer and free it after exit from the application.

Definition at line 66 of file free_atexit.c.

References free_list, free_size, malloc(), and realloc().

Referenced by leaky_calloc(), leaky_realloc(), and leaky_strdup().

Here is the call graph for this function:

void* leaky_realloc ( void *  old_memory,
size_t  size 
)

Reallocate memory, remember the new pointer and free it after exit from the application.

Definition at line 94 of file free_atexit.c.

References free_list, leaky_malloc(), and realloc().

Here is the call graph for this function:

char* leaky_strdup ( const char *  src)

strdup() using leaky_malloc().

Definition at line 116 of file free_atexit.c.

References leaky_malloc(), and len.

Here is the call graph for this function:

void leaky_uninit ( void  )

Free all allocations.

Definition at line 127 of file free_atexit.c.

References free_list, and free_size.

Referenced by leaky_init().


Variable Documentation

void** free_list = NULL [static]

Definition at line 58 of file free_atexit.c.

Referenced by leaky_malloc(), leaky_realloc(), and leaky_uninit().

leaky_idx_t free_size = 0 [static]

Definition at line 59 of file free_atexit.c.

Referenced by leaky_malloc(), and leaky_uninit().