X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fdmalloc.c;h=cbe190c77bcd3b52540bfc9c561d12c6bea7012e;hb=9e1a8a0a598aef894f59fa8abe3ccb144a5294a8;hp=c7f27544c039012a23b5e7796bd41b21ef3dbb84;hpb=f3dd50f81c9aed6768a88b253615d6667cd92a35;p=yaz-moved-to-github.git diff --git a/util/dmalloc.c b/util/dmalloc.c index c7f2754..cbe190c 100644 --- a/util/dmalloc.c +++ b/util/dmalloc.c @@ -1,10 +1,19 @@ /* - * Copyright (C) 1994, Index Data I/S - * All rights reserved. + * Copyright (c) 1995, Index Data + * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: dmalloc.c,v $ - * Revision 1.2 1995-04-10 10:23:50 quinn + * Revision 1.5 1995-05-16 08:51:10 quinn + * License, documentation, and memory fixes + * + * Revision 1.4 1995/05/15 13:25:13 quinn + * Fixed memory bug. + * + * Revision 1.3 1995/05/15 11:56:55 quinn + * Debuggng & adjustments. + * + * Revision 1.2 1995/04/10 10:23:50 quinn * Fixes. * * Revision 1.1 1995/03/27 08:35:17 quinn @@ -18,9 +27,9 @@ #include #include -static const unsigned long head = 0xaabbccdd; -static const unsigned long tail = 0x11223344; -static const unsigned long freed = 0xffeeffee; +static const unsigned char head[] = {44, 33, 22, 11}; +static const unsigned char tail[] = {11, 22, 33, 44}; +static const unsigned char freed[] = {99, 99, 99, 99}; void *d_malloc(char *file, int line, int nbytes) { @@ -45,7 +54,7 @@ void d_free(char *file, int line, char *ptr) if (memcmp(&head, ptr - 2 * sizeof(long), sizeof(long))) abort(); - memcpy(ptr, &freed, sizeof(long)); + memcpy(ptr - 2 * sizeof(long), &freed, sizeof(long)); memcpy(&len, ptr - sizeof(long), sizeof(long)); if (memcmp(ptr + len, &tail, sizeof(long))) abort(); @@ -66,17 +75,12 @@ void *d_realloc(char *file, int line, char *ptr, int nbytes) memcpy(&len, ptr - sizeof(long), sizeof(long)); if (memcmp(ptr + len, &tail, sizeof(long))) abort(); - if (!(r = realloc(ptr, nbytes + 3 * sizeof(long)))) + if (!(r = realloc(ptr - 2 * sizeof(long), nbytes + 3 * sizeof(long)))) return 0; fprintf(stderr, "---d_realloc, '%s':%d, %d->%d, %p->%p\n", file, line, len, nbytes, p, r + 2 * sizeof(long)); memcpy(r, &head, sizeof(long)); memcpy(r + sizeof(long), &nlen, sizeof(long)); - if (r != ptr - 2 * sizeof(long)) - { - memcpy(r + 2 * sizeof(long), ptr, len); - memcpy(ptr - 2 * sizeof(long), &freed, sizeof(long)); - } r += 2 * sizeof(long); memcpy(r + nbytes, &tail, sizeof(long)); return r;