summaryrefslogtreecommitdiffstats
path: root/generic/tclThreadAlloc.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2002-05-29 00:18:29 (GMT)
committerhobbs <hobbs>2002-05-29 00:18:29 (GMT)
commit255468e31d6c18b6e10f63c0d914101824c2ce7f (patch)
treede1fc3eaecbfd9ee3fb4978334ee4962cd8023c7 /generic/tclThreadAlloc.c
parentd3abfb7c31e20f560d6431c5dd6c91e327a7aee1 (diff)
downloadtcl-255468e31d6c18b6e10f63c0d914101824c2ce7f.zip
tcl-255468e31d6c18b6e10f63c0d914101824c2ce7f.tar.gz
tcl-255468e31d6c18b6e10f63c0d914101824c2ce7f.tar.bz2
* generic/tclThreadAlloc.c (TclpRealloc, TclpFree): protect
against the case when NULL is based.
Diffstat (limited to 'generic/tclThreadAlloc.c')
-rwxr-xr-xgeneric/tclThreadAlloc.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/generic/tclThreadAlloc.c b/generic/tclThreadAlloc.c
index 5a8a925..89bc9df 100755
--- a/generic/tclThreadAlloc.c
+++ b/generic/tclThreadAlloc.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclThreadAlloc.c,v 1.1 2002/04/23 17:03:34 hobbs Exp $ */
+ * RCS: @(#) $Id: tclThreadAlloc.c,v 1.2 2002/05/29 00:18:29 hobbs Exp $ */
#if defined(TCL_THREADS) && defined(USE_THREAD_ALLOC)
@@ -302,7 +302,7 @@ TclFreeAllocCache(void *arg)
char *
TclpAlloc(unsigned int reqsize)
{
- Cache *cachePtr = GetCache();
+ Cache *cachePtr = GetCache();
Block *blockPtr;
register int bucket;
size_t size;
@@ -365,32 +365,34 @@ TclpAlloc(unsigned int reqsize)
void
TclpFree(char *ptr)
{
- Cache *cachePtr = GetCache();
- Block *blockPtr;
- int bucket;
+ if (ptr != NULL) {
+ Cache *cachePtr = GetCache();
+ Block *blockPtr;
+ int bucket;
- /*
- * Get the block back from the user pointer and
- * call system free directly for large blocks.
- * Otherwise, push the block back on the bucket and
- * move blocks to the shared cache if there are now
- * too many free.
- */
+ /*
+ * Get the block back from the user pointer and
+ * call system free directly for large blocks.
+ * Otherwise, push the block back on the bucket and
+ * move blocks to the shared cache if there are now
+ * too many free.
+ */
- blockPtr = Ptr2Block(ptr);
- bucket = blockPtr->b_bucket;
- if (bucket == NBUCKETS) {
- cachePtr->nsysalloc -= blockPtr->b_reqsize;
- free(blockPtr);
- } else {
- cachePtr->buckets[bucket].nrequest -= blockPtr->b_reqsize;
- blockPtr->b_next = cachePtr->buckets[bucket].firstPtr;
- cachePtr->buckets[bucket].firstPtr = blockPtr;
- ++cachePtr->buckets[bucket].nfree;
- ++cachePtr->buckets[bucket].nput;
- if (cachePtr != sharedPtr &&
- cachePtr->buckets[bucket].nfree > binfo[bucket].maxblocks) {
- PutBlocks(cachePtr, bucket, binfo[bucket].nmove);
+ blockPtr = Ptr2Block(ptr);
+ bucket = blockPtr->b_bucket;
+ if (bucket == NBUCKETS) {
+ cachePtr->nsysalloc -= blockPtr->b_reqsize;
+ free(blockPtr);
+ } else {
+ cachePtr->buckets[bucket].nrequest -= blockPtr->b_reqsize;
+ blockPtr->b_next = cachePtr->buckets[bucket].firstPtr;
+ cachePtr->buckets[bucket].firstPtr = blockPtr;
+ ++cachePtr->buckets[bucket].nfree;
+ ++cachePtr->buckets[bucket].nput;
+ if (cachePtr != sharedPtr &&
+ cachePtr->buckets[bucket].nfree > binfo[bucket].maxblocks) {
+ PutBlocks(cachePtr, bucket, binfo[bucket].nmove);
+ }
}
}
}
@@ -421,6 +423,10 @@ TclpRealloc(char *ptr, unsigned int reqsize)
size_t size, min;
int bucket;
+ if (ptr == NULL) {
+ return TclpAlloc(reqsize);
+ }
+
/*
* If the block is not a system block and fits in place,
* simply return the existing pointer. Otherwise, if the block