RFA: open-related cleanup handling

Tom Tromey tromey@redhat.com
Thu Oct 30 21:53:00 GMT 2008


>>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:

Pedro> I noticed that discarding a _close cleanup is currently leaking the
Pedro> xmalloc'ed int used to hold the file descriptor.  Fixing it should be a
Pedro> matter of doing something similar to make_cleanup_restore_integer
Pedro> (using make_my_cleanup2) from inside make_cleanup_close.
Pedro> Would you like to take care of that while you have your hangs
Pedro> dirty doing these cleaning ups?

No problem.

How about this?  I used make_cleanup_dtor -- same difference though.

Built & regtested on x86-64 (compile farm).

What do you think of making make_my_cleanup and make_my_cleanup2 static?
They aren't used outside of utils.c.

Tom

2008-10-30  Tom Tromey  <tromey@redhat.com>

	* utils.c (make_cleanup_close): Use make_cleanup_dtor.
	(do_close_cleanup): Don't free 'fd'.

diff --git a/gdb/utils.c b/gdb/utils.c
index f9a5f19..26d7933 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -244,7 +244,6 @@ do_close_cleanup (void *arg)
 {
   int *fd = arg;
   close (*fd);
-  xfree (fd);
 }
 
 struct cleanup *
@@ -252,7 +251,7 @@ make_cleanup_close (int fd)
 {
   int *saved_fd = xmalloc (sizeof (fd));
   *saved_fd = fd;
-  return make_cleanup (do_close_cleanup, saved_fd);
+  return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
 }
 
 /* Helper function which does the work for make_cleanup_fclose.  */



More information about the Gdb-patches mailing list