[Libguestfs] [nbdkit PATCH] nbd: Fix memory leak

Eric Blake eblake at redhat.com
Sat Dec 2 17:52:31 UTC 2017


When converting from a single transaction to a linked list, I
forgot to free the storage for each member of the list.

Reported-by: Richard W.M. Jones <rjones at redhat.com>
Fixes: 7f5bb9bf13f041ea7702bda557d9dd668bc3423a
Signed-off-by: Eric Blake <eblake at redhat.com>
---

I'm still not sure why 'make check' passes while 'make check-valgrind'
fails for TESTS=test-nbd, but this at least avoids the memory leak.

 plugins/nbd/nbd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
index b844bf5..425abe4 100644
--- a/plugins/nbd/nbd.c
+++ b/plugins/nbd/nbd.c
@@ -334,6 +334,7 @@ nbd_reply_raw (struct handle *h, int *fd)
   }

   *fd = trans->u.fds[1];
+  free (trans);
   switch (be32toh (rep.error)) {
   case NBD_SUCCESS:
     if (trans->buf && read_full (h->fd, trans->buf, trans->count) < 0)
@@ -399,6 +400,7 @@ nbd_reader (void *handle)
       abort ();
     }
     close (trans->u.fds[1]);
+    free (trans);
   }
   return NULL;
 }
-- 
2.14.3




More information about the Libguestfs mailing list