summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorhobbs <hobbs>2001-06-28 01:22:21 (GMT)
committerhobbs <hobbs>2001-06-28 01:22:21 (GMT)
commit293dbdc050e3bd444292641282727a0bd24eef27 (patch)
tree913c84ddcaadd7359ee726c2c7be0a8aeb368389 /generic
parent2b6587fc6cf0bc144393a46fcf12967e8cdcbde6 (diff)
downloadtcl-293dbdc050e3bd444292641282727a0bd24eef27.zip
tcl-293dbdc050e3bd444292641282727a0bd24eef27.tar.gz
tcl-293dbdc050e3bd444292641282727a0bd24eef27.tar.bz2
* generic/tclInt.h:
* generic/tclObj.c: * unix/Makefile.in: added a -DPURIFY mode that makes Tcl_Obj's allocated and free singularly (instead of in alloc in blocks and never free) to allow checkers like Purify to operate better.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclInt.h33
-rw-r--r--generic/tclObj.c15
2 files changed, 45 insertions, 3 deletions
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 7af3c65..2ee93d0 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -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: tclInt.h,v 1.56 2001/06/17 03:48:19 dgp Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.57 2001/06/28 01:22:21 hobbs Exp $
*/
#ifndef _TCLINT
@@ -2183,6 +2183,37 @@ EXTERN int TclCompileWhileCmd _ANSI_ARGS_((Tcl_Interp *interp,
TclIncrObjsFreed(); \
}
+#elif defined(PURIFY)
+
+/*
+ * The PURIFY mode is like the regular mode, but instead of doing block
+ * Tcl_Obj allocation and keeping a freed list for efficiency, it always
+ * allocates and frees a single Tcl_Obj so that tools like Purify can
+ * better track memory leaks
+ */
+
+# define TclNewObj(objPtr) \
+ (objPtr) = (Tcl_Obj *) Tcl_Ckalloc(sizeof(Tcl_Obj)); \
+ (objPtr)->refCount = 0; \
+ (objPtr)->bytes = tclEmptyStringRep; \
+ (objPtr)->length = 0; \
+ (objPtr)->typePtr = NULL; \
+ TclIncrObjsAllocated();
+
+# define TclDecrRefCount(objPtr) \
+ if (--(objPtr)->refCount <= 0) { \
+ if (((objPtr)->bytes != NULL) \
+ && ((objPtr)->bytes != tclEmptyStringRep)) { \
+ ckfree((char *) (objPtr)->bytes); \
+ } \
+ if (((objPtr)->typePtr != NULL) \
+ && ((objPtr)->typePtr->freeIntRepProc != NULL)) { \
+ (objPtr)->typePtr->freeIntRepProc(objPtr); \
+ } \
+ ckfree((char *) (objPtr)); \
+ TclIncrObjsFreed(); \
+ }
+
#else /* not TCL_MEM_DEBUG */
#ifdef TCL_THREADS
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 21a4caf..09d9428 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.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: tclObj.c,v 1.22 2001/05/26 01:25:59 msofer Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.23 2001/06/28 01:22:21 hobbs Exp $
*/
#include "tclInt.h"
@@ -435,11 +435,15 @@ Tcl_NewObj()
*/
Tcl_MutexLock(&tclObjMutex);
+#ifdef PURIFY
+ objPtr = (Tcl_Obj *) Tcl_Ckalloc(sizeof(Tcl_Obj));
+#else
if (tclFreeObjList == NULL) {
TclAllocateFreeObjects();
}
objPtr = tclFreeObjList;
tclFreeObjList = (Tcl_Obj *) tclFreeObjList->internalRep.otherValuePtr;
+#endif
objPtr->refCount = 0;
objPtr->bytes = tclEmptyStringRep;
objPtr->length = 0;
@@ -553,6 +557,13 @@ TclAllocateFreeObjects()
register Tcl_Obj *prevPtr, *objPtr;
register int i;
+ /*
+ * This has been noted by Purify to be a potential leak. The problem is
+ * that Tcl, when not TCL_MEM_DEBUG compiled, keeps around all allocated
+ * Tcl_Obj's, pointed to by tclFreeObjList, when freed instead of
+ * actually freeing the memory. These never do get freed properly.
+ */
+
basePtr = (char *) ckalloc(bytesToAlloc);
memset(basePtr, 0, bytesToAlloc);
@@ -616,7 +627,7 @@ TclFreeObj(objPtr)
*/
Tcl_MutexLock(&tclObjMutex);
-#ifdef TCL_MEM_DEBUG
+#if defined(TCL_MEM_DEBUG) || defined(PURIFY)
ckfree((char *) objPtr);
#else
objPtr->internalRep.otherValuePtr = (VOID *) tclFreeObjList;