This is the mail archive of the gdb-patches@sourceware.cygnus.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH/RFA free(NULL) bomb in printcmd.c


Andrew Cagney wrote :
> Um, I'm confused.  wouldn't it be easier to just delete the two cleanup
> calls (the first, perhaphs, replaced with make_cleanup (null_cleanup,
> NULL))?

Of course.  But I did not know if the number of cleanups mattered, so I made
my change as small as possible.

[ 10 minutes reflexion and search ]

The current situation and my and your `fixes' would have caused memory leaks,
because the intention of the programmer there was actually to `free (name)'
and `free (filename)', but `make_cleanup' is called before `name' and `filename'
are allocated.
I now think I have the correct fix. OK to commit ?

Philippe De Muyter  <phdm@macqel.be>

	* printcmd.c (print_address_symbolic): Call `make_cleanup' with
	`(free_current_contents, &x)', not `(free, x)'.
	* utils.c (free_current_contents): Do not `free (NULL)'.

Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.3
diff -u -p -r1.3 printcmd.c
--- printcmd.c	2000/04/04 04:16:48	1.3
+++ printcmd.c	2000/04/11 08:35:26
@@ -562,9 +562,10 @@ print_address_symbolic (addr, stream, do
   int offset = 0;
   int line = 0;
 
-  struct cleanup *cleanup_chain = make_cleanup (free, name);
+  struct cleanup *cleanup_chain =
+    make_cleanup ((make_cleanup_func) free_current_contents, &name);
   if (print_symbol_filename)
-    make_cleanup (free, filename);
+    make_cleanup ((make_cleanup_func) free_current_contents, &filename);
 
   if (build_address_symbolic (addr, do_demangle, &name, &offset, &filename, &line, &unmapped))
     return;
Index: gdb/utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.6
diff -u -p -r1.6 utils.c
--- utils.c	2000/03/30 18:54:28	1.6
+++ utils.c	2000/04/11 08:36:17
@@ -378,7 +378,8 @@ void
 free_current_contents (location)
      char **location;
 {
-  free (*location);
+  if (*location)
+    free (*location);
 }
 
 /* Provide a known function that does nothing, to use as a base for

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]