9pfs: fix potential host memory leak in v9fs_read
PATCH 1/1 9pfs: fix potential host memory leak in v9fs_read
From: Li Qiang <[email protected]>
In 9pfs read dispatch function, it doesn't free two QEMUIOVector object thus causing potential memory leak. This patch avoid this.
--- hw/9pfs/9p.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/9pfs/9p.c +4 -0
@@ -1830,12 +1830,16 @@ static void v9fs_read(void *opaque) }while (len == -EINTR && !pdu->cancelled);if (len <0 ) {/* IO error return the error */ +qemu_iovec_destroy (&qiov); +qemu_iovec_destroy (&qiov_full); err = len; goto out; } }while (count < max_count && len >0 ); err =pdu_marshal (pdu, offset,"d" , count);if (err <0 ) { +qemu_iovec_destroy (&qiov); +qemu_iovec_destroy (&qiov_full); goto out; } err += offset + count;
Signature · 1 line
1.8.3.1
Quoted 5 lines · On Mon, 26 Sep 2016 21:42:26 -0700 Li Qiang <[email protected]> wrote:
From: Li Qiang <[email protected]>
In 9pfs read dispatch function, it doesn't free two QEMUIOVector object thus causing potential memory leak. This patch avoid this.
Good catch for the leak, but I'd prefer another fix. See below.
Quoted 10 lines
Signed-off-by Li Qiang <[email protected]>--- hw/9pfs/9p.c | 4 ++++ 1 file changed, 4 insertions(+)hw/9pfs/9p.c +0
-0
hw/9pfs/9p.c static void v9fs_read(void *opaque) · line 1834
Quoted 5 lines
hw/9pfs/9p.c +2
-0@@ -1830,12 +1830,16 @@ static void v9fs_read(void *opaque) }while (len == -EINTR && !pdu->cancelled);if (len <0 ) {/* IO error return the error */ +qemu_iovec_destroy (&qiov); +qemu_iovec_destroy (&qiov_full);
We already have these lines at the end of the code block for type P9_FID_FILE.
Let's introduce an out_free_iovec: label and...
hw/9pfs/9p.c static void v9fs_read(void *opaque) · line 1836
Quoted 2 lines
hw/9pfs/9p.c +0
-0err = len; goto out;
goto out_free_iovec;
hw/9pfs/9p.c static void v9fs_read(void *opaque) · line 1843
Quoted 7 lines
hw/9pfs/9p.c +2
-0} }while (count < max_count && len >0 ); err =pdu_marshal (pdu, offset,"d" , count);if (err <0 ) { +qemu_iovec_destroy (&qiov); +qemu_iovec_destroy (&qiov_full); goto out;
Same here.
hw/9pfs/9p.c static void v9fs_read(void *opaque) · line 1845
Quoted 2 lines
hw/9pfs/9p.c +0
-0} err += offset + count;
As a valuable side effect, the error will be traced :)
Cheers.
--
Greg