]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
After a fork, gdbserver_init can be called again.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 28 Feb 2012 22:37:44 +0000 (22:37 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 28 Feb 2012 22:37:44 +0000 (22:37 +0000)
Buffers should not be re-allocated in such a case.
(memory leak detected by running memcheck on memcheck)

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12410

coregrind/m_gdbserver/server.c
coregrind/m_gdbserver/target.c

index 9d2467fba8d3abd15e2d8f341910f22afe278a02..84a2e1b290d493f38b1f7556fa51c31a28627283 100644 (file)
@@ -719,8 +719,12 @@ void gdbserver_init (void)
    dlog(1, "gdbserver_init gdbserver embedded in valgrind: %s\n", version);
    noack_mode = False;
    initialize_low ();
-   own_buf = malloc (PBUFSIZ);
-   mem_buf = malloc (PBUFSIZ);
+   // After a fork, gdbserver_init can be called again.
+   // We do not have to re-malloc the buffers in such a case.
+   if (own_buf == NULL)
+      own_buf = malloc (PBUFSIZ);
+   if (mem_buf == NULL)
+      mem_buf = malloc (PBUFSIZ);
 }
 
 void gdbserver_terminate (void)
index ae61c94c6a56b5b19b522761cac9ba8a9a804dbf..c72c761bf37dfebf861e0bb56500b8eabf7d0d96 100644 (file)
@@ -91,7 +91,9 @@ int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
 
 void set_target_ops (struct target_ops *target)
 {
-   the_target = (struct target_ops *) malloc (sizeof (*the_target));
+   // Can be called again after a fork => do not re-malloc the_target.
+   if (the_target == NULL)
+      the_target = (struct target_ops *) malloc (sizeof (*the_target));
    VG_(memcpy) (the_target, target, sizeof (*the_target));
 }