diff options
author | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
---|---|---|
committer | Thomas Vander Stichele <thomas@apestaart.org> | 2004-03-14 22:34:33 +0000 |
commit | 7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2 (patch) | |
tree | f863b467dea9559a6ec9c48affbfae11f8104164 /ext/tarkin/mem.c | |
parent | a19db4bbdc4a15ea0d8f4d28e9a1302c9c3d1657 (diff) | |
download | gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.gz gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.bz2 gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.zip |
gst-indent
Original commit message from CVS:
gst-indent
Diffstat (limited to 'ext/tarkin/mem.c')
-rw-r--r-- | ext/tarkin/mem.c | 192 |
1 files changed, 99 insertions, 93 deletions
diff --git a/ext/tarkin/mem.c b/ext/tarkin/mem.c index 2c304b7a..6b337ef3 100644 --- a/ext/tarkin/mem.c +++ b/ext/tarkin/mem.c @@ -10,11 +10,12 @@ #if defined(DBG_MEMLEAKS) -typedef struct { - void *mem; - char *allocated_in_func; - char *allocated_in_file; - unsigned int allocated_in_line; +typedef struct +{ + void *mem; + char *allocated_in_func; + char *allocated_in_file; + unsigned int allocated_in_line; } MemDesc; @@ -23,124 +24,129 @@ static int alloc_count = 0; static MemDesc *alloc_list = NULL; -static -void dbg_memleaks_done (int exitcode, void *dummy) +static void +dbg_memleaks_done (int exitcode, void *dummy) { - unsigned int i; - (void) dummy; - - if (exitcode == 0 && alloc_count != 0) { - fprintf (stderr, "\nmemory leak detected !!!\n"); - fprintf (stderr, "\nalloc_count == %i\n\n", alloc_count); - for (i=0; i<alloc_count; i++) { - MemDesc *d = &alloc_list[i]; - fprintf (stderr, "chunk %p allocated in %s (%s: %u) not free'd !!\n", - d->mem, d->allocated_in_func, d->allocated_in_file, - d->allocated_in_line); - } - free(alloc_list); - } - fprintf (stderr, "\n"); + unsigned int i; + + (void) dummy; + + if (exitcode == 0 && alloc_count != 0) { + fprintf (stderr, "\nmemory leak detected !!!\n"); + fprintf (stderr, "\nalloc_count == %i\n\n", alloc_count); + for (i = 0; i < alloc_count; i++) { + MemDesc *d = &alloc_list[i]; + + fprintf (stderr, "chunk %p allocated in %s (%s: %u) not free'd !!\n", + d->mem, d->allocated_in_func, d->allocated_in_file, + d->allocated_in_line); + } + free (alloc_list); + } + fprintf (stderr, "\n"); } -static -void dbg_memleaks_init (void) +static void +dbg_memleaks_init (void) { - on_exit (dbg_memleaks_done, NULL); - initialized = 1; + on_exit (dbg_memleaks_done, NULL); + initialized = 1; } -void* dbg_malloc (char* file, int line, char *func, size_t bytes) +void * +dbg_malloc (char *file, int line, char *func, size_t bytes) { - void *mem = (void*) malloc (bytes); - MemDesc *d; + void *mem = (void *) malloc (bytes); + MemDesc *d; - if (!initialized) - dbg_memleaks_init(); + if (!initialized) + dbg_memleaks_init (); - alloc_count++; - alloc_list = realloc (alloc_list, alloc_count * sizeof(MemDesc)); + alloc_count++; + alloc_list = realloc (alloc_list, alloc_count * sizeof (MemDesc)); - d = &alloc_list[alloc_count-1]; - d->mem = mem; - d->allocated_in_func = func; - d->allocated_in_file = file; - d->allocated_in_line = line; + d = &alloc_list[alloc_count - 1]; + d->mem = mem; + d->allocated_in_func = func; + d->allocated_in_file = file; + d->allocated_in_line = line; - return mem; + return mem; } -void* dbg_calloc (char* file, int line, char *func, size_t count, size_t bytes) +void * +dbg_calloc (char *file, int line, char *func, size_t count, size_t bytes) { - void *mem = (void*) calloc (count, bytes); - MemDesc *d; + void *mem = (void *) calloc (count, bytes); + MemDesc *d; - if (!initialized) - dbg_memleaks_init(); + if (!initialized) + dbg_memleaks_init (); - alloc_count++; - alloc_list = realloc (alloc_list, alloc_count * sizeof(MemDesc)); + alloc_count++; + alloc_list = realloc (alloc_list, alloc_count * sizeof (MemDesc)); - d = &alloc_list[alloc_count-1]; - d->mem = mem; - d->allocated_in_func = func; - d->allocated_in_file = file; - d->allocated_in_line = line; + d = &alloc_list[alloc_count - 1]; + d->mem = mem; + d->allocated_in_func = func; + d->allocated_in_file = file; + d->allocated_in_line = line; - return mem; + return mem; } -void* dbg_realloc (char *file, int line, char *func, char *what, - void *mem, size_t bytes) +void * +dbg_realloc (char *file, int line, char *func, char *what, + void *mem, size_t bytes) { - unsigned int i; - - for (i=0; i<alloc_count; i++) { - if (alloc_list[i].mem == mem) { - alloc_list[i].mem = (void*) realloc (mem, bytes); - return alloc_list[i].mem; - } - } - - if (mem != NULL) { - fprintf (stderr, - "%s: trying to reallocate unknown chunk %p (%s)\n" - " in %s (%s: %u) !!!\n", - __FUNCTION__, mem, what, func, file, line); - exit (-1); - } - - return dbg_malloc(file, line, func, bytes); + unsigned int i; + + for (i = 0; i < alloc_count; i++) { + if (alloc_list[i].mem == mem) { + alloc_list[i].mem = (void *) realloc (mem, bytes); + return alloc_list[i].mem; + } + } + + if (mem != NULL) { + fprintf (stderr, + "%s: trying to reallocate unknown chunk %p (%s)\n" + " in %s (%s: %u) !!!\n", + __FUNCTION__, mem, what, func, file, line); + exit (-1); + } + + return dbg_malloc (file, line, func, bytes); } -void dbg_free (char *file, int line, char *func, char *what, void *mem) +void +dbg_free (char *file, int line, char *func, char *what, void *mem) { - unsigned int i; - - if (!initialized) - dbg_memleaks_init(); - - for (i=0; i<alloc_count; i++) { - if (alloc_list[i].mem == mem) { - free (mem); - alloc_count--; - memmove (&alloc_list[i], &alloc_list[i+1], - (alloc_count - i) * sizeof(MemDesc)); - return; - } - } - - fprintf (stderr, "%s: trying to free unknown chunk %p (%s)\n" - " in %s (%s: %u) !!!\n", - __FUNCTION__, mem, what, func, file, line); - exit (-1); + unsigned int i; + + if (!initialized) + dbg_memleaks_init (); + + for (i = 0; i < alloc_count; i++) { + if (alloc_list[i].mem == mem) { + free (mem); + alloc_count--; + memmove (&alloc_list[i], &alloc_list[i + 1], + (alloc_count - i) * sizeof (MemDesc)); + return; + } + } + + fprintf (stderr, "%s: trying to free unknown chunk %p (%s)\n" + " in %s (%s: %u) !!!\n", + __FUNCTION__, mem, what, func, file, line); + exit (-1); } #endif - |