diff options
author | Pixel <Pixel> | 2002-08-18 01:38:23 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-08-18 01:38:23 +0000 |
commit | 396239cc78a75ba7be739788485319c92b07d827 (patch) | |
tree | cd3e9ef485c1026e40b909c1989ef662cde30f5f /generic/Exceptions.cpp | |
parent | 11bf45f50739afb923829b3cc32efb9c8c009613 (diff) |
Blehaurg
Diffstat (limited to 'generic/Exceptions.cpp')
-rw-r--r-- | generic/Exceptions.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp index 564362e..f24c0fb 100644 --- a/generic/Exceptions.cpp +++ b/generic/Exceptions.cpp @@ -82,15 +82,16 @@ void * xmalloc(size_t s) throw (GeneralException) { return 0; } - if (!(r = (char *) ::malloc(s + sizeof(size_t)))) { - throw MemoryException(s + sizeof(size_t)); + if (!(r = (char *) ::malloc(s + 2 * sizeof(size_t)))) { + throw MemoryException(s + 2 * sizeof(size_t)); } - memset(r, 0, s + sizeof(size_t)); + memset(r, 0, s + 2 * sizeof(size_t)); *((size_t *)r) = s; + *(((size_t *)r) + 1) = 0xdeedbeef; - return (void *)(r + sizeof(size_t)); + return (void *)(r + 2 * sizeof(size_t)); } void * xrealloc(void * ptr, size_t s) { @@ -118,15 +119,16 @@ void * xrealloc(void * ptr, size_t s) { #endif void xfree(void *& p) { - if (p) { - ::free(((char *)p) - sizeof(size_t)); - p = 0; - } + xfree(((char *)p)); } void xfree(char *& p) { if (p) { - ::free(p - sizeof(size_t)); + if (*(((size_t *)p) - 1) != 0xdeedbeef) { + fprintf(stderr, "Error: trying to xfree() a non xmalloc()ed bloc.\n"); + exit(-1); + } + ::free(p - 2 * sizeof(size_t)); p = 0; } } |