X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fxpdf%2Fgmem.c;h=a0f2cf540e05d0e93e6e18278f0949ac8174503e;hb=c26ca847941ca0acfc9f3b4bdc519d904ba09a39;hp=663e69c18dc4ae78935ee39eae158e1ebd8ad35a;hpb=195800383723343bb7f1fbc1f327bedd2aee0253;p=swftools.git diff --git a/pdf2swf/xpdf/gmem.c b/pdf2swf/xpdf/gmem.c index 663e69c..a0f2cf5 100644 --- a/pdf2swf/xpdf/gmem.c +++ b/pdf2swf/xpdf/gmem.c @@ -3,15 +3,15 @@ * * Memory routines with out-of-memory checking. * - * Copyright 1996-2002 Glyph & Cog, LLC + * Copyright 1996-2003 Glyph & Cog, LLC */ +#include #include #include #include #include -#include "./aconf.h" -#include "./gmem.h" +#include "gmem.h" #ifdef DEBUG_MEM @@ -50,6 +50,7 @@ static GMemHdr *gMemList[gMemNLists] = { static int gMemIndex = 0; static int gMemAlloc = 0; +static int gMemInUse = 0; #endif /* DEBUG_MEM */ @@ -78,6 +79,7 @@ void *gmalloc(int size) { hdr->next = gMemList[lst]; gMemList[lst] = hdr; ++gMemAlloc; + gMemInUse += size; for (p = (unsigned long *)data; p <= trl; ++p) *p = gMemDeadVal; return data; @@ -135,6 +137,28 @@ void *grealloc(void *p, int size) { #endif } +void *gmallocn(int nObjs, int objSize) { + int n; + + n = nObjs * objSize; + if (objSize == 0 || n / objSize != nObjs) { + fprintf(stderr, "Bogus memory allocation size\n"); + exit(1); + } + return gmalloc(n); +} + +void *greallocn(void *p, int nObjs, int objSize) { + int n; + + n = nObjs * objSize; + if (objSize == 0 || n / objSize != nObjs) { + fprintf(stderr, "Bogus memory allocation size\n"); + exit(1); + } + return grealloc(p, n); +} + void gfree(void *p) { #ifdef DEBUG_MEM int size; @@ -156,6 +180,7 @@ void gfree(void *p) { else gMemList[lst] = hdr->next; --gMemAlloc; + gMemInUse -= hdr->size; size = gMemDataSize(hdr->size); trl = (unsigned long *)((char *)hdr + gMemHdrSize + size); if (*trl != gMemDeadVal) {