diff options
author | Julian Smith <julian.smith@artifex.com> | 2022-01-26 17:13:29 +0000 |
---|---|---|
committer | Julian Smith <julian.smith@artifex.com> | 2022-02-03 17:03:14 +0000 |
commit | 08aa1b42d078c5760c18a5e35ab9d76e076ca718 (patch) | |
tree | f4e0a13fe1915decab10ffadd94c6aca31a30788 /base/memento.c | |
parent | da1899ee329d96eb8f1d3d8ed104d9b5e9d276dc (diff) | |
download | ghostpdl-08aa1b42d078c5760c18a5e35ab9d76e076ca718.tar.gz |
base/memento.c: limit output of detailed blocks, and optionally abort after corruption.
If memento.showDetailedBlocks is positive, showInfo() now decrements it
and returns 1 immediately if it reaches zero. So for example setting
MEMENTO_SHOW_DETAILED_BLOCKS=10 limits the max number of detailed block
diagostics to 10. showDetailedBlocks now defaults to -1 which shows all blocks
as before.
In Memento_Internal_checkAllAlloced(), call abort() if we find corruption and
memento.abortOnCorruption is true.
Also fixed warning from clang and gcc for initialisation of Memento_hashedST's
trace[1] array.
Diffstat (limited to 'base/memento.c')
-rw-r--r-- | base/memento.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/base/memento.c b/base/memento.c index 94b2d616b..890ef0da5 100644 --- a/base/memento.c +++ b/base/memento.c @@ -1030,7 +1030,7 @@ static Memento_hashedST oom_hashed_st = NULL, /* next */ 0, /* hash */ 0, /* count */ - NULL /* trace[0] */ + {NULL}/* trace[0] */ }; static Memento_hashedST *Memento_getHashedStacktrace(void) @@ -2130,6 +2130,13 @@ static int showInfo(Memento_BlkHeader *b, void *arg) } fprintf(stderr, " Event %d (%s)\n", details->sequence, eventType[(int)details->type]); Memento_showHashedStacktrace(details->trace); + if (memento.showDetailedBlocks > 0) { + memento.showDetailedBlocks -= 1; + if (memento.showDetailedBlocks == 0) { + fprintf(stderr, "Stopping display of block details because memento.showDetailedBlocks is now zero.\n"); + return 1; + } + } } return 0; } @@ -2436,7 +2443,7 @@ static void Memento_init(void) memento.pattern = (env ? atoi(env) : 0); env = getenv("MEMENTO_SHOW_DETAILED_BLOCKS"); - memento.showDetailedBlocks = (env ? atoi(env) : 1); + memento.showDetailedBlocks = (env ? atoi(env) : -1); env = getenv("MEMENTO_HIDE_MULTIPLE_REALLOCS"); memento.hideMultipleReallocs = (env ? atoi(env) : 0); @@ -3957,6 +3964,10 @@ static int Memento_Internal_checkAllAlloced(Memento_BlkHeader *memblk, void *arg fprintf(stderr, "corrupted.\n " "Block last checked OK at allocation %d. Now %d.\n", memblk->lastCheckedOK, memento.sequence); + if (memento.abortOnCorruption) { + fprintf(stderr, "*** memblk corrupted, calling abort()\n"); + abort(); + } data->preCorrupt = 0; data->postCorrupt = 0; data->freeCorrupt = 0; |