/* -*- mode: C; c-basic-offset: 4 -*- */ #ident "Copyright (c) 2007 Tokutek Inc. All rights reserved." #include "memory.h" #include #include #include #include #include int toku_memory_check=0; #define WHEN_MEM_DEBUG(x) ({if (toku_memory_check) ({x});}) static long long n_items_malloced=0; /* Memory checking */ enum { items_limit = 1000 }; static int overflowed=0; static void *items[items_limit]; static long sizes[items_limit]; static void note_did_malloc (void *p, long size) { static long long count=0; WHEN_MEM_DEBUG( if (n_items_malloced%p\n", __FILE__, __LINE__, nmemb, size, r); note_did_malloc(r, nmemb*size); //if ((long)r==0x80523f8) { printf("%s:%d %p\n", __FILE__, __LINE__, r); } return r; } #define FREELIST_LIMIT (64+1) static void *freelist[FREELIST_LIMIT]; #define MALLOC_SIZE_COUNTING_LIMIT 512 static int malloc_counts[MALLOC_SIZE_COUNTING_LIMIT]; // We rely on static variables being initialized to 0. static int fresh_malloc_counts[MALLOC_SIZE_COUNTING_LIMIT]; // We rely on static variables being initialized to 0. static int other_malloc_count=0, fresh_other_malloc_count=0; void *toku_malloc(unsigned long size) { void * r; errno=0; if (size=sizeof(void*) && size%p\n", __FILE__, __LINE__, size,r); note_did_malloc(r, size); //if ((long)r==0x80523f8) { printf("%s:%d %p size=%ld\n", __FILE__, __LINE__, r, size); } return r; } void *toku_tagmalloc(unsigned long size, int typtag) { //printf("%s:%d tagmalloc\n", __FILE__, __LINE__); void *r = toku_malloc(size); assert(size>sizeof(int)); ((int*)r)[0] = typtag; return r; } void *toku_realloc(void *p, long size) { void *newp; note_did_free(p); errno=0; newp = actual_realloc(p, size); //printf("%s:%d realloc(%p,%ld)-->%p\n", __FILE__, __LINE__, p, size, newp); note_did_malloc(newp, size); return newp; } void toku_free(void* p) { //printf("%s:%d free(%p)\n", __FILE__, __LINE__, p); note_did_free(p); actual_free(p); } void toku_free_n(void* p, unsigned long size) { //printf("%s:%d free(%p)\n", __FILE__, __LINE__, p); note_did_free(p); if (size>=sizeof(void*) && size0) { printf("n_items_malloced=%lld\n", n_items_malloced); if (toku_memory_check) printf(" one item is %p size=%ld\n", items[0], sizes[0]); } assert(n_items_malloced==0); } int toku_get_n_items_malloced (void) { return n_items_malloced; } void toku_print_malloced_items (void) { int i; for (i=0; i