Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

gwmem-check.c File Reference

#include "gw-config.h"
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <execinfo.h>
#include "gwlib.h"

Include dependency graph for gwmem-check.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  location
struct  area

Defines

#define NEW_AREA_PATTERN   0xcafebabe
#define FREE_AREA_PATTERN   0xdeadbeef
#define START_MARK_PATTERN   0xdadaface
#define END_MARK_PATTERN   0xadadafec
#define MAX_DUMP   16
#define MARKER_SIZE   16
#define MAX_TAB_SIZE   (100*1024*1024L)
#define MAX_ALLOCATIONS   ((long) (MAX_TAB_SIZE/sizeof(struct area)))
#define FREE_RING_SIZE   1024

Functions

void lock (void)
void unlock (void)
unsigned long round_pow2 (unsigned long num)
void fill (unsigned char *p, size_t bytes, long pattern)
int untouched (unsigned char *p, size_t bytes, long pattern)
void endmark (unsigned char *p, size_t size)
void startmark (unsigned char *p, long number)
long check_startmark (unsigned char *p)
int check_endmark (unsigned char *p, size_t size)
int check_marks (struct area *area, long index)
void dump_area (struct area *area)
areafind_area (unsigned char *p)
void change_total_size (long change)
arearecord_allocation (unsigned char *p, size_t size, const char *filename, long lineno, const char *function)
void remove_allocation (struct area *area)
void drop_from_free_ring (long index)
void put_on_free_ring (struct area *area)
void free_area (struct area *area)
void gw_check_init_mem (int slow_flag)
void gw_check_shutdown (void)
void * gw_check_malloc (size_t size, const char *filename, long lineno, const char *function)
void * gw_check_realloc (void *p, size_t size, const char *filename, long lineno, const char *function)
void gw_check_free (void *p, const char *filename, long lineno, const char *function)
char * gw_check_strdup (const char *str, const char *filename, long lineno, const char *function)
void * gw_check_claim_area (void *p, const char *filename, long lineno, const char *function)
void gw_check_check_leaks (void)
int gw_check_is_allocated (void *p)
long gw_check_area_size (void *p)

Variables

int initialized = 0
int slow = 0
Mutex gwmem_lock
area allocated [MAX_ALLOCATIONS]
area free_ring [FREE_RING_SIZE]
long num_allocations
long free_ring_start
long free_ring_len
long highest_num_allocations
long highest_total_size
long total_size


Define Documentation

#define END_MARK_PATTERN   0xadadafec
 

Definition at line 121 of file gwmem-check.c.

Referenced by check_endmark(), and endmark().

#define FREE_AREA_PATTERN   0xdeadbeef
 

Definition at line 114 of file gwmem-check.c.

Referenced by drop_from_free_ring(), find_area(), and free_area().

#define FREE_RING_SIZE   1024
 

Definition at line 174 of file gwmem-check.c.

#define MARKER_SIZE   16
 

Definition at line 163 of file gwmem-check.c.

Referenced by check_endmark(), check_startmark(), drop_from_free_ring(), endmark(), gw_check_malloc(), gw_check_realloc(), and startmark().

#define MAX_ALLOCATIONS   ((long) (MAX_TAB_SIZE/sizeof(struct area)))
 

Definition at line 167 of file gwmem-check.c.

#define MAX_DUMP   16
 

Definition at line 124 of file gwmem-check.c.

Referenced by dump_area().

#define MAX_TAB_SIZE   (100*1024*1024L)
 

Definition at line 166 of file gwmem-check.c.

#define NEW_AREA_PATTERN   0xcafebabe
 

Definition at line 110 of file gwmem-check.c.

Referenced by find_area(), gw_check_malloc(), and gw_check_realloc().

#define START_MARK_PATTERN   0xdadaface
 

Definition at line 118 of file gwmem-check.c.

Referenced by check_startmark(), find_area(), and startmark().


Function Documentation

void change_total_size long  change  )  [static]
 

Definition at line 410 of file gwmem-check.c.

References highest_total_size, and total_size.

Referenced by gw_check_realloc(), record_allocation(), and remove_allocation().

00411 {
00412     total_size += change;
00413     if (total_size > highest_total_size)
00414         highest_total_size = total_size;
00415 }

int check_endmark unsigned char *  p,
size_t  size
[static]
 

Definition at line 285 of file gwmem-check.c.

References END_MARK_PATTERN, MARKER_SIZE, size, and untouched().

Referenced by check_marks(), and find_area().

00286 {
00287     if (!untouched(p + size, MARKER_SIZE, END_MARK_PATTERN))
00288         return -1;
00289     return 0;
00290 }

Here is the call graph for this function:

int check_marks struct area area,
long  index
[static]
 

Definition at line 292 of file gwmem-check.c.

References area::area, area::area_size, check_endmark(), check_startmark(), error(), and result.

Referenced by drop_from_free_ring(), gw_check_check_leaks(), and remove_allocation().

00293 {
00294     int result = 0;
00295 
00296     if (check_startmark(area->area) != index) {
00297         error(0, "Start marker was damaged for area %ld", index);
00298         result = -1;
00299     }
00300     if (check_endmark(area->area, area->area_size) < 0) {
00301         error(0, "End marker was damaged for area %ld", index);
00302         result = -1;
00303     }
00304 
00305     return result;
00306 }

Here is the call graph for this function:

long check_startmark unsigned char *  p  )  [static]
 

Definition at line 275 of file gwmem-check.c.

References MARKER_SIZE, number, START_MARK_PATTERN, and untouched().

Referenced by check_marks(), and find_area().

00276 {
00277     long number;
00278     if (!untouched(p - MARKER_SIZE + sizeof(long),
00279                    MARKER_SIZE - sizeof(long), START_MARK_PATTERN))
00280         return -1;
00281     memcpy(&number, p - MARKER_SIZE, sizeof(number));
00282     return number;
00283 }

Here is the call graph for this function:

void drop_from_free_ring long  index  )  [static]
 

Definition at line 461 of file gwmem-check.c.

References area::area, area::area_size, check_marks(), dump_area(), error(), free, FREE_AREA_PATTERN, free_ring, MARKER_SIZE, and untouched().

Referenced by gw_check_check_leaks(), and put_on_free_ring().

00462 {
00463     struct area *area;
00464 
00465     area = &free_ring[index];
00466     if (check_marks(area, index) < 0 ||
00467         !untouched(area->area, area->area_size, FREE_AREA_PATTERN)) {
00468         error(0, "Freed area %p has been tampered with.", area->area);
00469         dump_area(area);
00470     }
00471     free((unsigned char *)area->area - MARKER_SIZE);
00472 }

Here is the call graph for this function:

void dump_area struct area area  )  [static]
 

Definition at line 308 of file gwmem-check.c.

References area::allocator, area::area, area::area_size, area::claimer, debug(), location::filename, area::frame_size, area::frames, free, location::function, location::lineno, MAX_DUMP, area::max_size, and area::reallocator.

Referenced by drop_from_free_ring(), find_area(), and gw_check_check_leaks().

00309 {
00310     debug("gwlib.gwmem", 0, "Area %p, size %ld, max_size %ld",
00311           area->area, (long) area->area_size, (long) area->max_size);
00312     debug("gwlib.gwmem", 0, "Allocated by %s() at %s:%ld",
00313           area->allocator.function,
00314           area->allocator.filename,
00315           area->allocator.lineno);
00316     if (area->reallocator.function) {
00317         debug("gwlib.gwmem", 0, "Re-allocated by %s() at %s:%ld",
00318               area->reallocator.function,
00319               area->reallocator.filename,
00320               area->reallocator.lineno);
00321     }
00322     if (area->claimer.function) {
00323         debug("gwlib.gwmem", 0, "Claimed by %s() at %s:%ld",
00324               area->claimer.function,
00325               area->claimer.filename,
00326               area->claimer.lineno);
00327     }
00328     if (area->area_size > 0) {
00329         size_t i;
00330         unsigned char *p;
00331         char buf[MAX_DUMP * 3 + 1];
00332 
00333         p = area->area;
00334         buf[0] = '\0';
00335         for (i = 0; i < area->area_size && i < MAX_DUMP; ++i)
00336             sprintf(strchr(buf, '\0'), "%02x ", p[i]);
00337 
00338         debug("gwlib.gwmem", 0, "Contents of area (first %d bytes):", MAX_DUMP);
00339         debug("gwlib.gwmem", 0, "  %s", buf);
00340     }
00341 #if HAVE_BACKTRACE
00342     {
00343         size_t i;
00344         char **strings = backtrace_symbols(area->frames, area->frame_size);
00345         debug("gwlib.gwmem", 0, "Backtrace of last malloc/realloc:");
00346         for (i = 0; i < area->frame_size; i++) {
00347             if (strings != NULL)
00348                 debug("gwlib.gwmem", 0, "%s", strings[i]);
00349             else
00350                 debug("gwlib.gwmem", 0, "%p", area->frames[i]);
00351         }
00352         free(strings);
00353     }
00354 #endif
00355 }

Here is the call graph for this function:

void endmark unsigned char *  p,
size_t  size
[inline, static]
 

Definition at line 254 of file gwmem-check.c.

References END_MARK_PATTERN, fill(), MARKER_SIZE, and size.

Referenced by gw_check_realloc(), and record_allocation().

00255 {
00256     fill(p + size, MARKER_SIZE, END_MARK_PATTERN);
00257 }

Here is the call graph for this function:

void fill unsigned char *  p,
size_t  bytes,
long  pattern
[static]
 

Definition at line 228 of file gwmem-check.c.

Referenced by endmark(), free_area(), gw_check_malloc(), gw_check_realloc(), and startmark().

00229 {
00230     while (bytes > sizeof(pattern)) {
00231         memcpy(p, &pattern, sizeof(pattern));
00232         p += sizeof(pattern);
00233         bytes -= sizeof(pattern);
00234     }
00235     if (bytes > 0)
00236         memcpy(p, &pattern, bytes);
00237 }

struct area* find_area unsigned char *  p  )  [static]
 

Definition at line 357 of file gwmem-check.c.

References allocated, area::area, area::area_size, check_endmark(), check_startmark(), dump_area(), error(), FREE_AREA_PATTERN, gw_assert, NEW_AREA_PATTERN, num_allocations, slow, and START_MARK_PATTERN.

Referenced by gw_check_area_size(), gw_check_claim_area(), gw_check_free(), gw_check_is_allocated(), and gw_check_realloc().

00358 {
00359     long index;
00360     struct area *area;
00361     long suspicious_pointer;
00362     unsigned long p_ul;
00363 
00364     gw_assert(p != NULL);
00365 
00366     p_ul = (unsigned long) p;
00367     suspicious_pointer =
00368         (sizeof(p) == sizeof(long) &&
00369          (p_ul == NEW_AREA_PATTERN || p_ul == FREE_AREA_PATTERN ||
00370       p_ul == START_MARK_PATTERN || p_ul == END_MARK_PATTERN));
00371 
00372     if (slow || suspicious_pointer) {
00373         /* Extra check, which does not touch the (perhaps not allocated)
00374      * memory area.  It's slow, but may help pinpoint problems that
00375      * would otherwise cause segfaults. */
00376         for (index = 0; index < num_allocations; index++) {
00377             if (allocated[index].area == p)
00378                 break;
00379         }
00380         if (index == num_allocations) {
00381             error(0, "Area %p not found in allocation table.", p);
00382             return NULL;
00383         }
00384     }
00385 
00386     index = check_startmark(p);
00387     if (index >= 0 && index < num_allocations &&
00388         allocated[index].area == p) {
00389         area = &allocated[index];
00390         if (check_endmark(p, area->area_size) < 0) {
00391             error(0, "End marker was damaged for area %p", p);
00392             dump_area(area);
00393         }
00394         return area;
00395     }
00396 
00397     error(0, "Start marker was damaged for area %p", p);
00398     for (index = 0; index < num_allocations; index++) {
00399         if (allocated[index].area == p) {
00400             area = &allocated[index];
00401             dump_area(area);
00402             return area;
00403         }
00404     }
00405 
00406     error(0, "Could not find area information.");
00407     return NULL;
00408 }

Here is the call graph for this function:

void free_area struct area area  )  [static]
 

Definition at line 493 of file gwmem-check.c.

References area::area, area::area_size, fill(), FREE_AREA_PATTERN, put_on_free_ring(), and remove_allocation().

Referenced by gw_check_free(), and gw_check_realloc().

00494 {
00495     fill(area->area, area->area_size, FREE_AREA_PATTERN);
00496     put_on_free_ring(area);
00497     remove_allocation(area);
00498 }

Here is the call graph for this function:

long gw_check_area_size void *  p  ) 
 

Definition at line 696 of file gwmem-check.c.

References area::area_size, find_area(), lock, size, unlock, and warning().

00697 {
00698     struct area *area;
00699     size_t size;
00700 
00701     lock();
00702     area = find_area(p);
00703     if (!area) {
00704         unlock();
00705         warning(0, "Area_size called on non-allocated area %p", p);
00706         return -1;
00707     }
00708     size = area->area_size;
00709     unlock();
00710     return size;
00711 }

Here is the call graph for this function:

void gw_check_check_leaks void   ) 
 

Definition at line 652 of file gwmem-check.c.

References allocated, area::area_size, check_marks(), debug(), drop_from_free_ring(), dump_area(), free_ring_len, gw_assert, highest_num_allocations, highest_total_size, initialized, lock, num_allocations, total_size, and unlock.

00653 {
00654     long calculated_size;
00655     long index;
00656 
00657     gw_assert(initialized);
00658     lock();
00659 
00660     for (index = 0; index < free_ring_len; index++) {
00661         drop_from_free_ring(index);
00662     }
00663     free_ring_len = 0;
00664 
00665     calculated_size = 0;
00666     for (index = 0; index < num_allocations; index++) {
00667         calculated_size += allocated[index].area_size;
00668     }
00669     gw_assert(calculated_size == total_size);
00670 
00671     debug("gwlib.gwmem", 0, "----------------------------------------");
00672     debug("gwlib.gwmem", 0, "Current allocations: %ld areas, %ld bytes",
00673           num_allocations, total_size);
00674     debug("gwlib.gwmem", 0, "Highest number of allocations: %ld areas",
00675           highest_num_allocations);
00676     debug("gwlib.gwmem", 0, "Highest memory usage: %ld bytes",
00677           highest_total_size);
00678     for (index = 0; index < num_allocations; index++) {
00679         check_marks(&allocated[index], index);
00680         dump_area(&allocated[index]);
00681     }
00682 
00683     unlock();
00684 }

Here is the call graph for this function:

void* gw_check_claim_area void *  p,
const char *  filename,
long  lineno,
const char *  function
 

Definition at line 627 of file gwmem-check.c.

References area::claimer, location::filename, find_area(), location::function, location::lineno, lock, panic, and unlock.

00629 {
00630     struct area *area;
00631 
00632     /* Allow this for the convenience of wrapper macros. */
00633     if (p == NULL)
00634         return NULL;
00635 
00636     lock();
00637     area = find_area(p);
00638     if (!area) {
00639         unlock();
00640         panic(0, "Claim_area called on non-allocated area");
00641     }
00642 
00643     area->claimer.filename = filename;
00644     area->claimer.lineno = lineno;
00645     area->claimer.function = function;
00646     unlock();
00647 
00648     /* For convenience of calling macros */
00649     return p;
00650 }

Here is the call graph for this function:

void gw_check_free void *  p,
const char *  filename,
long  lineno,
const char *  function
 

Definition at line 594 of file gwmem-check.c.

References find_area(), free_area(), gw_assert, initialized, lock, panic, and unlock.

00596 {
00597     struct area *area;
00598     gw_assert(initialized);
00599 
00600     if (p == NULL)
00601         return;
00602 
00603     lock();
00604     area = find_area(p);
00605     if (!area) {
00606         unlock();
00607         panic(0, "Free called on non-allocated area");
00608     }
00609 
00610     free_area(area);
00611     unlock();
00612 }

Here is the call graph for this function:

void gw_check_init_mem int  slow_flag  ) 
 

Definition at line 500 of file gwmem-check.c.

References gwmem_lock, initialized, mutex_init_static, and slow.

00501 {
00502     mutex_init_static(&gwmem_lock);
00503     slow = slow_flag;
00504     initialized = 1;
00505 }

int gw_check_is_allocated void *  p  ) 
 

Definition at line 686 of file gwmem-check.c.

References find_area(), lock, and unlock.

00687 {
00688     struct area *area;
00689 
00690     lock();
00691     area = find_area(p);
00692     unlock();
00693     return area != NULL;
00694 }

Here is the call graph for this function:

void* gw_check_malloc size_t  size,
const char *  filename,
long  lineno,
const char *  function
 

Definition at line 513 of file gwmem-check.c.

References filename, fill(), gw_assert, initialized, lock, malloc, MARKER_SIZE, NEW_AREA_PATTERN, panic, record_allocation(), size, and unlock.

Referenced by gw_check_realloc(), and gw_check_strdup().

00515 {
00516     unsigned char *p;
00517 
00518     gw_assert(initialized);
00519 
00520     /* ANSI C89 says malloc(0) is implementation-defined.  Avoid it. */
00521     gw_assert(size > 0);
00522 
00523     p = malloc(size + 2 * MARKER_SIZE);
00524     if (p == NULL)
00525         panic(errno, "Memory allocation of %ld bytes failed.", (long)size);
00526     p += MARKER_SIZE;
00527 
00528     lock();
00529     fill(p, size, NEW_AREA_PATTERN);
00530     record_allocation(p, size, filename, lineno, function);
00531     unlock();
00532 
00533     return p;
00534 }

Here is the call graph for this function:

void* gw_check_realloc void *  p,
size_t  size,
const char *  filename,
long  lineno,
const char *  function
 

Definition at line 536 of file gwmem-check.c.

References area::allocator, area::area_size, change_total_size(), endmark(), filename, location::filename, fill(), find_area(), free_area(), location::function, gw_assert, gw_check_malloc(), initialized, location::lineno, lock, malloc, MARKER_SIZE, area::max_size, NEW_AREA_PATTERN, panic, area::reallocator, record_allocation(), round_pow2(), size, and unlock.

00538 {
00539     struct area *area;
00540 
00541     if (p == NULL)
00542         return gw_check_malloc(size, filename, lineno, function);
00543 
00544     gw_assert(initialized);
00545     gw_assert(size > 0);
00546 
00547     lock();
00548     area = find_area(p);
00549     if (!area) {
00550         unlock();
00551         panic(0, "Realloc called on non-allocated area");
00552     }
00553 
00554     if (size == area->area_size) {
00555         /* No changes */
00556     } else if (size <= area->max_size) {
00557         change_total_size(size - area->area_size);
00558         area->area_size = size;
00559         endmark(p, size);
00560     } else if (size > area->max_size) {
00561         /* The current block is not large enough for the reallocation.
00562          * We will allocate a new block, copy the data over, and free
00563          * the old block.  We round the size up to a power of two,
00564          * to prevent frequent reallocations. */
00565         struct area *new_area;
00566         size_t new_size;
00567         unsigned char *new_p;
00568 
00569         new_size = round_pow2(size + 2 * MARKER_SIZE);
00570         new_p = malloc(new_size);
00571         new_size -= 2 * MARKER_SIZE;
00572         new_p += MARKER_SIZE;
00573         memcpy(new_p, p, area->area_size);
00574         fill(new_p + area->area_size, size - area->area_size,
00575              NEW_AREA_PATTERN);
00576         new_area = record_allocation(new_p, size,
00577                                      area->allocator.filename,
00578                                      area->allocator.lineno,
00579                                      area->allocator.function);
00580         new_area->max_size = new_size;
00581         free_area(area);
00582 
00583         p = new_p;
00584         area = new_area;
00585     }
00586 
00587     area->reallocator.filename = filename;
00588     area->reallocator.lineno = lineno;
00589     area->reallocator.function = function;
00590     unlock();
00591     return p;
00592 }

Here is the call graph for this function:

void gw_check_shutdown void   ) 
 

Definition at line 507 of file gwmem-check.c.

References gwmem_lock, initialized, and mutex_destroy().

00508 {
00509     mutex_destroy(&gwmem_lock);
00510     initialized = 0;
00511 }

Here is the call graph for this function:

char* gw_check_strdup const char *  str,
const char *  filename,
long  lineno,
const char *  function
 

Definition at line 614 of file gwmem-check.c.

References filename, gw_assert, gw_check_malloc(), and initialized.

00616 {
00617     char *copy;
00618 
00619     gw_assert(initialized);
00620     gw_assert(str != NULL);
00621 
00622     copy = gw_check_malloc(strlen(str) + 1, filename, lineno, function);
00623     strcpy(copy, str);
00624     return copy;
00625 }

Here is the call graph for this function:

void lock void   )  [inline, static]
 

Definition at line 197 of file gwmem-check.c.

References gwmem_lock, and mutex_lock.

00198 {
00199     mutex_lock(&gwmem_lock);
00200 }

void put_on_free_ring struct area area  )  [static]
 

Definition at line 474 of file gwmem-check.c.

References area::area, drop_from_free_ring(), free_ring, free_ring_len, free_ring_start, and startmark().

Referenced by free_area().

00475 {
00476     /* Simple case: We're still filling the free ring. */
00477     if (free_ring_len < FREE_RING_SIZE) {
00478         free_ring[free_ring_len] = *area;
00479         startmark(area->area, free_ring_len);
00480         free_ring_len++;
00481         return;
00482     }
00483 
00484     /* Normal case: We need to check and release a free ring entry,
00485      * then put this one in its place. */
00486 
00487     drop_from_free_ring(free_ring_start);
00488     free_ring[free_ring_start] = *area;
00489     startmark(area->area, free_ring_start);
00490     free_ring_start = (free_ring_start + 1) % FREE_RING_SIZE;
00491 }

Here is the call graph for this function:

struct area* record_allocation unsigned char *  p,
size_t  size,
const char *  filename,
long  lineno,
const char *  function
[static]
 

Definition at line 417 of file gwmem-check.c.

References allocated, area::allocator, area::area, area::area_size, change_total_size(), endmark(), location::filename, area::frame_size, area::frames, location::function, highest_num_allocations, location::lineno, area::max_size, num_allocations, panic, size, and startmark().

Referenced by gw_check_malloc(), and gw_check_realloc().

00419 {
00420     struct area *area;
00421     static struct area empty_area;
00422 
00423     if (num_allocations == MAX_ALLOCATIONS) {
00424         panic(0, "Too many concurrent allocations.");
00425     }
00426 
00427     area = &allocated[num_allocations];
00428     *area = empty_area;
00429     area->area = p;
00430     area->area_size = size;
00431     area->max_size = size;
00432     area->allocator.filename = filename;
00433     area->allocator.lineno = lineno;
00434     area->allocator.function = function;
00435 #if HAVE_BACKTRACE
00436     area->frame_size = backtrace(area->frames, sizeof(area->frames) / sizeof(void*));
00437 #endif
00438 
00439     startmark(area->area, num_allocations);
00440     endmark(area->area, area->area_size);
00441 
00442     num_allocations++;
00443     if (num_allocations > highest_num_allocations)
00444         highest_num_allocations = num_allocations;
00445     change_total_size(size);
00446 
00447     return area;
00448 }

Here is the call graph for this function:

void remove_allocation struct area area  )  [static]
 

Definition at line 450 of file gwmem-check.c.

References allocated, area::area, area::area_size, change_total_size(), check_marks(), num_allocations, and startmark().

Referenced by free_area().

00451 {
00452     change_total_size(-1*area->area_size);
00453     num_allocations--;
00454     if (area == &allocated[num_allocations])
00455         return;
00456     check_marks(&allocated[num_allocations], num_allocations);
00457     *area = allocated[num_allocations];
00458     startmark(area->area, area - allocated);
00459 }

Here is the call graph for this function:

unsigned long round_pow2 unsigned long  num  )  [static]
 

Definition at line 207 of file gwmem-check.c.

Referenced by gw_check_realloc().

00208 {
00209     unsigned long i;
00210 
00211     if (num <= 16)
00212         return 16;
00213 
00214     for (i = 32; i < 0x80000000L; i <<= 1) {
00215         if (num <= i)
00216             return i;
00217     }
00218 
00219     /* We have to handle this case separately; the loop cannot go that
00220      * far because i would overflow. */
00221     if (num <= 0x80000000L)
00222         return 0x80000000L;
00223 
00224     return 0xffffffffL;
00225 }

void startmark unsigned char *  p,
long  number
[static]
 

Definition at line 262 of file gwmem-check.c.

References fill(), gw_assert, MARKER_SIZE, number, and START_MARK_PATTERN.

Referenced by put_on_free_ring(), record_allocation(), and remove_allocation().

00263 {
00264     gw_assert(MARKER_SIZE >= sizeof(long));
00265     gw_assert(number >= 0);
00266 
00267     fill(p - MARKER_SIZE, sizeof(long), number);
00268     fill(p - MARKER_SIZE + sizeof(long),
00269          MARKER_SIZE - sizeof(long), START_MARK_PATTERN);
00270 }

Here is the call graph for this function:

void unlock void   )  [inline, static]
 

Definition at line 202 of file gwmem-check.c.

References gwmem_lock, and mutex_unlock.

00203 {
00204     mutex_unlock(&gwmem_lock);
00205 }

int untouched unsigned char *  p,
size_t  bytes,
long  pattern
[static]
 

Definition at line 240 of file gwmem-check.c.

Referenced by check_endmark(), check_startmark(), and drop_from_free_ring().

00241 {
00242     while (bytes > sizeof(pattern)) {
00243         if (memcmp(p, &pattern, sizeof(pattern)) != 0)
00244             return 0;
00245         p += sizeof(pattern);
00246         bytes -= sizeof(pattern);
00247     }
00248     if (bytes > 0 && memcmp(p, &pattern, bytes) != 0)
00249         return 0;
00250     return 1;
00251 }


Variable Documentation

struct area allocated[MAX_ALLOCATIONS] [static]
 

Definition at line 176 of file gwmem-check.c.

Referenced by find_area(), gw_check_check_leaks(), record_allocation(), and remove_allocation().

struct area free_ring[FREE_RING_SIZE] [static]
 

Definition at line 177 of file gwmem-check.c.

Referenced by drop_from_free_ring(), and put_on_free_ring().

long free_ring_len [static]
 

Definition at line 185 of file gwmem-check.c.

Referenced by gw_check_check_leaks(), and put_on_free_ring().

long free_ring_start [static]
 

Definition at line 184 of file gwmem-check.c.

Referenced by put_on_free_ring().

Mutex gwmem_lock [static]
 

Definition at line 134 of file gwmem-check.c.

Referenced by gw_check_init_mem(), gw_check_shutdown(), lock(), and unlock().

long highest_num_allocations [static]
 

Definition at line 189 of file gwmem-check.c.

Referenced by gw_check_check_leaks(), and record_allocation().

long highest_total_size [static]
 

Definition at line 191 of file gwmem-check.c.

Referenced by change_total_size(), and gw_check_check_leaks().

int initialized = 0 [static]
 

Definition at line 126 of file gwmem-check.c.

Referenced by gw_check_check_leaks(), gw_check_free(), gw_check_init_mem(), gw_check_malloc(), gw_check_realloc(), gw_check_shutdown(), and gw_check_strdup().

long num_allocations [static]
 

Definition at line 181 of file gwmem-check.c.

Referenced by find_area(), gw_check_check_leaks(), record_allocation(), and remove_allocation().

int slow = 0 [static]
 

Definition at line 129 of file gwmem-check.c.

Referenced by find_area(), and gw_check_init_mem().

long total_size [static]
 

Definition at line 193 of file gwmem-check.c.

Referenced by change_total_size(), and gw_check_check_leaks().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.