diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-02-19 16:32:39 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-02-19 16:32:39 -0800 |
commit | 634c9b963c109c772f3ba913d4abd328093059bc (patch) | |
tree | d0059f0b94ccf5a4f33ad933e9f9b2cb847a8ad5 /src/corruptionCheck.js | |
parent | 6dfcace48a061dd93643a4da4647591d73bdcc31 (diff) |
handle malloc(0) and free(0) in corruption checker
Diffstat (limited to 'src/corruptionCheck.js')
-rw-r--r-- | src/corruptionCheck.js | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/corruptionCheck.js b/src/corruptionCheck.js index ae2a0bdf..bd3b240b 100644 --- a/src/corruptionCheck.js +++ b/src/corruptionCheck.js @@ -19,8 +19,8 @@ var CorruptionChecker = { } }); }, malloc: function(size) { + if (size <= 0) size = 1; // malloc(0) sometimes happens - just allocate a larger area, no harm CorruptionChecker.checkAll(); - assert(size > 0); // some mallocs accept zero - fix your code if you want to use this tool size = (size+7)&(~7); var allocation = CorruptionChecker.realMalloc(size*(1+2*CorruptionChecker.BUFFER_FACTOR)); var ptr = allocation + size*CorruptionChecker.BUFFER_FACTOR; @@ -28,13 +28,17 @@ var CorruptionChecker = { CorruptionChecker.ptrs[ptr] = size; CorruptionChecker.fillBuffer(allocation, size*CorruptionChecker.BUFFER_FACTOR); CorruptionChecker.fillBuffer(allocation + size*(1+CorruptionChecker.BUFFER_FACTOR), size*CorruptionChecker.BUFFER_FACTOR); + //Module.print('malloc ' + size + ' ==> ' + [ptr, allocation]); return ptr; }, free: function(ptr) { + if (!ptr) return; // ok to free(NULL), does nothing CorruptionChecker.checkAll(); var size = CorruptionChecker.ptrs[ptr]; + //Module.print('free ' + ptr + ' of size ' + size); assert(size); var allocation = ptr - size*CorruptionChecker.BUFFER_FACTOR; + //Module.print('free ' + ptr + ' of size ' + size + ' and allocation ' + allocation); delete CorruptionChecker.ptrs[ptr]; CorruptionChecker.realFree(allocation); }, |