diff: fix bug with memory profiling and interactive queries

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Mar 31 22:25:38 AEST 1999


The diff below is the same as the one in my earlier mail.
The only thing that is new is the log message.

--------------------

Estimated hours taken: 3

runtime/mercury_heap_profile.c:
	When inserting new nodes into the heap profiling table,
	allocate a new copy of the procedure name string, rather
	than just copying the pointer.  This is needed in case
	the procedure name string is later deallocated.  The
	procedure name string will normally be a string literal,
	but even then, if it was in a dynamically loaded module
	it may still be deallocated, using dlclose().

Index: runtime/mercury_heap_profile.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap_profile.c,v
retrieving revision 1.1
diff -u -r1.1 mercury_heap_profile.c
--- mercury_heap_profile.c	1997/12/05 15:56:34	1.1
+++ mercury_heap_profile.c	1999/03/31 12:17:40
@@ -89,7 +89,16 @@
 	*/
 	if (!found) {
 		node = MR_PROF_NEW(MR_memprof_record);
-		node->name = name;
+		/*
+		** We need to make a fresh copy of the name,
+		** rather than just copying the pointer, because
+		** our caller may deallocate its copy of the name.
+		** Normally the name will be a string literal,
+		** but even then it might be a string literal from
+		** a dlopen()'ed module which will later get dlclose()'d.
+		*/
+		node->name = MR_PROF_NEW_ARRAY(char, strlen(name) + 1);
+		strcpy(node->name, name);
 		node->addr = addr;
 		node->left = NULL;
 		node->right = NULL;

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list