X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fxmalloc.c;h=5f9b519c48947560b6030b3c9aa863f70f69bbb0;hb=c39a893dfdae5f792139177132e7e7a70e010aa7;hp=60dbc2c4b44ee7b67e967e1f1009cdebe25630c2;hpb=695e6df9fce9b838cb3fe8f49b211ed99943caef;p=yaz-moved-to-github.git diff --git a/util/xmalloc.c b/util/xmalloc.c index 60dbc2c..5f9b519 100644 --- a/util/xmalloc.c +++ b/util/xmalloc.c @@ -1,9 +1,9 @@ /* - * Copyright (C) 1994-2001, Index Data + * Copyright (C) 1994-2003, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Id: xmalloc.c,v 1.16 2002-04-16 13:04:20 heikki Exp $ + * $Id: xmalloc.c,v 1.19 2003-05-16 13:14:26 adam Exp $ */ #if HAVE_CONFIG_H @@ -23,9 +23,9 @@ #if TRACE_XMALLOC > 1 -static const unsigned char head[] = {44, 33, 22, 11}; -static const unsigned char tail[] = {11, 22, 33, 44}; -static const unsigned char freed[] = {11, 22, 33, 44}; +static const unsigned char head[] = {88, 77, 66, 55, 44, 33, 22, 11}; +static const unsigned char tail[] = {11, 22, 33, 44, 55, 66, 77, 88}; +static const unsigned char freed[] = {11, 22, 33, 44, 55, 66, 77, 88}; struct dmalloc_info { int len; @@ -42,7 +42,7 @@ void *xmalloc_d(size_t nbytes, const char *file, int line) char *res; struct dmalloc_info *dinfo; - if (!(res = (char*) malloc(nbytes + sizeof(*dinfo)+8*sizeof(char)))) + if (!(res = (char*) malloc(nbytes + sizeof(*dinfo)+16*sizeof(char)))) return 0; dinfo = (struct dmalloc_info *) res; strncpy (dinfo->file, file, sizeof(dinfo->file)-1); @@ -56,9 +56,9 @@ void *xmalloc_d(size_t nbytes, const char *file, int line) dinfo->next->prev = dinfo; dmalloc_list = dinfo; - memcpy(res + sizeof(*dinfo), head, 4*sizeof(char)); - res += sizeof(*dinfo) + 4*sizeof(char); - memcpy(res + nbytes, tail, 4*sizeof(char)); + memcpy(res + sizeof(*dinfo), head, 8*sizeof(char)); + res += sizeof(*dinfo) + 8*sizeof(char); + memcpy(res + nbytes, tail, 8*sizeof(char)); return res; } @@ -69,13 +69,13 @@ void xfree_d(void *ptr, const char *file, int line) if (!ptr) return; dinfo = (struct dmalloc_info *) - ((char*)ptr - 4*sizeof(char) - sizeof(*dinfo)); - if (memcmp(head, (char*) ptr - 4*sizeof(char), 4*sizeof(char))) + ((char*)ptr - 8*sizeof(char) - sizeof(*dinfo)); + if (memcmp(head, (char*) ptr - 8*sizeof(char), 8*sizeof(char))) { yaz_log(LOG_FATAL, "xfree_d bad head, %s:%d, %p", file, line, ptr); abort(); } - if (memcmp((char*) ptr + dinfo->len, tail, 4*sizeof(char))) + if (memcmp((char*) ptr + dinfo->len, tail, 8*sizeof(char))) { yaz_log(LOG_FATAL, "xfree_d bad tail, %s:%d, %p", file, line, ptr); abort(); @@ -86,7 +86,7 @@ void xfree_d(void *ptr, const char *file, int line) dmalloc_list = dinfo->next; if (dinfo->next) dinfo->next->prev = dinfo->prev; - memcpy ((char*) ptr - 4*sizeof(char), freed, 4*sizeof(char)); + memcpy ((char*) ptr - 8*sizeof(char), freed, 8*sizeof(char)); free(dinfo); return; } @@ -101,18 +101,18 @@ void *xrealloc_d(void *p, size_t nbytes, const char *file, int line) { if (!nbytes) return 0; - res = (char *) malloc(nbytes + sizeof(*dinfo) + 8*sizeof(char)); + res = (char *) malloc(nbytes + sizeof(*dinfo) + 16*sizeof(char)); } else { - if (memcmp(head, ptr - 4*sizeof(char), 4*sizeof(char))) + if (memcmp(head, ptr - 8*sizeof(char), 8*sizeof(char))) { yaz_log(LOG_FATAL, "xrealloc_d bad head, %s:%d, %p", file, line, ptr); abort(); } - dinfo = (struct dmalloc_info *) (ptr-4*sizeof(char) - sizeof(*dinfo)); - if (memcmp(ptr + dinfo->len, tail, 4*sizeof(char))) + dinfo = (struct dmalloc_info *) (ptr-8*sizeof(char) - sizeof(*dinfo)); + if (memcmp(ptr + dinfo->len, tail, 8*sizeof(char))) { yaz_log(LOG_FATAL, "xrealloc_d bad tail, %s:%d, %p", file, line, ptr); @@ -131,7 +131,7 @@ void *xrealloc_d(void *p, size_t nbytes, const char *file, int line) return 0; } res = (char *) - realloc(dinfo, nbytes + sizeof(*dinfo) + 8*sizeof(char)); + realloc(dinfo, nbytes + sizeof(*dinfo) + 16*sizeof(char)); } if (!res) return 0; @@ -147,9 +147,9 @@ void *xrealloc_d(void *p, size_t nbytes, const char *file, int line) dmalloc_list->prev = dinfo; dmalloc_list = dinfo; - memcpy(res + sizeof(*dinfo), head, 4*sizeof(char)); - res += sizeof(*dinfo) + 4*sizeof(char); - memcpy(res + nbytes, tail, 4*sizeof(char)); + memcpy(res + sizeof(*dinfo), head, 8*sizeof(char)); + res += sizeof(*dinfo) + 8*sizeof(char); + memcpy(res + nbytes, tail, 8*sizeof(char)); return res; } @@ -159,7 +159,7 @@ void *xcalloc_d(size_t nmemb, size_t size, const char *file, int line) struct dmalloc_info *dinfo; size_t nbytes = nmemb * size; - if (!(res = (char*) calloc(1, nbytes+sizeof(*dinfo)+8*sizeof(char)))) + if (!(res = (char*) calloc(1, nbytes+sizeof(*dinfo)+16*sizeof(char)))) return 0; dinfo = (struct dmalloc_info *) res; strncpy (dinfo->file, file, sizeof(dinfo->file)-1); @@ -173,9 +173,9 @@ void *xcalloc_d(size_t nmemb, size_t size, const char *file, int line) dinfo->next->prev = dinfo; dmalloc_list = dinfo; - memcpy(res + sizeof(*dinfo), head, 4*sizeof(char)); - res += sizeof(*dinfo) + 4*sizeof(char); - memcpy(res + nbytes, tail, 4*sizeof(char)); + memcpy(res + sizeof(*dinfo), head, 8*sizeof(char)); + res += sizeof(*dinfo) + 8*sizeof(char); + memcpy(res + nbytes, tail, 8*sizeof(char)); return res; } @@ -184,15 +184,15 @@ void xmalloc_trav_d(const char *file, int line) size_t size = 0; struct dmalloc_info *dinfo = dmalloc_list; - yaz_log (LOG_LOG, "malloc_trav %s:%d", file, line); + yaz_log (LOG_MALLOC, "malloc_trav %s:%d", file, line); while (dinfo) { - yaz_log (LOG_LOG, " %20s:%d p=%p size=%d", dinfo->file, dinfo->line, - ((char*) dinfo)+sizeof(*dinfo)+4*sizeof(char), dinfo->len); + yaz_log (LOG_MALLOC, " %20s:%d p=%p size=%d", dinfo->file, dinfo->line, + ((char*) dinfo)+sizeof(*dinfo)+8*sizeof(char), dinfo->len); size += dinfo->len; dinfo = dinfo->next; } - yaz_log (LOG_LOG, "total bytes %ld", (long) size); + yaz_log (LOG_MALLOC, "total bytes %ld", (long) size); } #else