[tip:tools/kvm] kvm tools, 9p: Fix memory leak in virtio_p9_walk()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  36054b07b8612b15406d3c54d1fc227918451f8c
Gitweb:     http://git.kernel.org/tip/36054b07b8612b15406d3c54d1fc227918451f8c
Author:     Pekka Enberg <penberg@xxxxxxxxxx>
AuthorDate: Tue, 3 Jan 2012 19:39:14 +0200
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Tue, 3 Jan 2012 19:39:14 +0200

kvm tools, 9p: Fix memory leak in virtio_p9_walk()

This patch fixes the following valgrind reported memory leak in
virtio_9p_walk():

  ==6689== 1,058 bytes in 134 blocks are definitely lost in loss record 39 of 47
  ==6689==    at 0x4A0649D: malloc (vg_replace_malloc.c:236)
  ==6689==    by 0x4116A9: virtio_p9_pdu_readf (9p-pdu.c:110)
  ==6689==    by 0x40FB9F: virtio_p9_walk (9p.c:305)
  ==6689==    by 0x410E73: virtio_p9_do_io (9p.c:1151)
  ==6689==    by 0x40DB45: thread_pool__threadfunc (threadpool.c:56)
  ==6689==    by 0x3DE7007B30: start_thread (in /lib64/libpthread-2.14.so)
  ==6689==    by 0x3DE68DFD2C: clone (in /lib64/libc-2.14.so)

Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/virtio/9p.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c
index 8e37925..3d1c624 100644
--- a/tools/kvm/virtio/9p.c
+++ b/tools/kvm/virtio/9p.c
@@ -280,7 +280,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev,
 {
 	u8 i;
 	u16 nwqid;
-	char *str;
 	u16 nwname;
 	struct p9_qid wqid;
 	struct p9_fid *new_fid;
@@ -301,11 +300,15 @@ static void virtio_p9_walk(struct p9_dev *p9dev,
 			struct stat st;
 			char tmp[PATH_MAX] = {0};
 			char full_path[PATH_MAX];
+			char *str;
 
 			virtio_p9_pdu_readf(pdu, "s", &str);
 
 			/* Format the new path we're 'walk'ing into */
 			sprintf(tmp, "%s/%s", new_fid->path, str);
+
+			free(str);
+
 			if (lstat(rel_to_abs(p9dev, tmp, full_path), &st) < 0)
 				goto err_out;
 
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux