aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Schoenebeck <qemu_oss@crudebyte.com>2023-04-29 11:25:33 +0200
committerChristian Schoenebeck <qemu_oss@crudebyte.com>2023-05-16 16:21:54 +0200
commitf91ce58cb2eba96192bdbd730e7a0952873f6c05 (patch)
tree7904764cd71807767724ab009a57572275a042f8 /tests
parent1a67e07fe984e3bc9fe4b25a212e879b02e114cb (diff)
downloadqemu-f91ce58cb2eba96192bdbd730e7a0952873f6c05.zip
qemu-f91ce58cb2eba96192bdbd730e7a0952873f6c05.tar.gz
qemu-f91ce58cb2eba96192bdbd730e7a0952873f6c05.tar.bz2
tests/9p: fix potential leak in v9fs_rreaddir()
Free allocated directory entries in v9fs_rreaddir() if argument `entries` was passed as NULL, to avoid a memory leak. It is explicitly allowed by design for `entries` to be NULL. [1] [1] https://lore.kernel.org/all/1690923.g4PEXVpXuU@silver Reported-by: Coverity (CID 1487558) Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Reviewed-by: Greg Kurz <groug@kaod.org> Message-Id: <E1psh5T-0002XN-1C@lizzy.crudebyte.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qtest/libqos/virtio-9p-client.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/virtio-9p-client.c
index e4a368e..b8adc8d 100644
--- a/tests/qtest/libqos/virtio-9p-client.c
+++ b/tests/qtest/libqos/virtio-9p-client.c
@@ -594,6 +594,8 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
{
uint32_t local_count;
struct V9fsDirent *e = NULL;
+ /* only used to avoid a leak if entries was NULL */
+ struct V9fsDirent *unused_entries = NULL;
uint16_t slen;
uint32_t n = 0;
@@ -612,6 +614,8 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
e = g_new(struct V9fsDirent, 1);
if (entries) {
*entries = e;
+ } else {
+ unused_entries = e;
}
} else {
e = e->next = g_new(struct V9fsDirent, 1);
@@ -628,6 +632,7 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries,
*nentries = n;
}
+ v9fs_free_dirents(unused_entries);
v9fs_req_free(req);
}