[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 11/37] blockdev: fix drive_init() opts and bs_opts
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL v2 11/37] blockdev: fix drive_init() opts and bs_opts leaks |
Date: |
Fri, 8 Nov 2013 11:12:05 +0100 |
These memory leaks also make drive_add if=none,id=drive0 without a file=
option leak the options list. This keeps ID "drive0" around forever.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
blockdev.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index b260477..86e6bff 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -341,7 +341,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
qemu_opts_absorb_qdict(opts, bs_opts, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
- return NULL;
+ goto early_err;
}
if (id) {
@@ -361,7 +361,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
if ((buf = qemu_opt_get(opts, "discard")) != NULL) {
if (bdrv_parse_discard_flags(buf, &bdrv_flags) != 0) {
error_setg(errp, "invalid discard option");
- return NULL;
+ goto early_err;
}
}
@@ -383,7 +383,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
/* this is the default */
} else {
error_setg(errp, "invalid aio option");
- return NULL;
+ goto early_err;
}
}
#endif
@@ -393,13 +393,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
error_printf("Supported formats:");
bdrv_iterate_format(bdrv_format_print, NULL);
error_printf("\n");
- return NULL;
+ goto early_err;
}
drv = bdrv_find_format(buf);
if (!drv) {
error_setg(errp, "'%s' invalid format", buf);
- return NULL;
+ goto early_err;
}
}
@@ -435,20 +435,20 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
if (!check_throttle_config(&cfg, &error)) {
error_propagate(errp, error);
- return NULL;
+ goto early_err;
}
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type !=
IF_NONE) {
error_setg(errp, "werror is not supported by this bus type");
- return NULL;
+ goto early_err;
}
on_write_error = parse_block_error_action(buf, 0, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
- return NULL;
+ goto early_err;
}
}
@@ -456,13 +456,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type !=
IF_NONE) {
error_report("rerror is not supported by this bus type");
- return NULL;
+ goto early_err;
}
on_read_error = parse_block_error_action(buf, 1, &error);
if (error_is_set(&error)) {
error_propagate(errp, error);
- return NULL;
+ goto early_err;
}
}
@@ -491,6 +491,8 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
if (has_driver_specific_opts) {
file = NULL;
} else {
+ QDECREF(bs_opts);
+ qemu_opts_del(opts);
return dinfo;
}
}
@@ -529,12 +531,13 @@ static DriveInfo *blockdev_init(QDict *bs_opts,
return dinfo;
err:
- qemu_opts_del(opts);
- QDECREF(bs_opts);
bdrv_unref(dinfo->bdrv);
g_free(dinfo->id);
QTAILQ_REMOVE(&drives, dinfo, next);
g_free(dinfo);
+early_err:
+ QDECREF(bs_opts);
+ qemu_opts_del(opts);
return NULL;
}
--
1.8.3.1
- [Qemu-devel] [PULL v2 29/37] block: vhdx - remove BAT file offset bit shifting, (continued)
- [Qemu-devel] [PULL v2 29/37] block: vhdx - remove BAT file offset bit shifting, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 30/37] block: vhdx - move more endian translations to vhdx-endian.c, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 03/37] block/raw-posix: fix FreeBSD compilation, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 32/37] block: vhdx - fix comment typos in header, fix incorrect struct fields, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 07/37] block: qemu-iotests, add quotes to $TEST_IMG usage in 019, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 08/37] block: qemu-iotests, removes duplicate double quotes in 039, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 33/37] block: vhdx - add .bdrv_create() support, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 37/37] block: Round up total_sectors, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 10/37] block: qemu-iotests, add quotes to $TEST_IMG usage in 061, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 36/37] block: vhdx qemu-iotest - log replay of data sector, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 11/37] blockdev: fix drive_init() opts and bs_opts leaks,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL v2 15/37] qdev-monitor-test: add device_add leak test cases, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 21/37] block: vhdx - log support struct and defines, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 22/37] block: vhdx - break endian translation functions out, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 26/37] block: vhdx - add region overlap detection for image files, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 28/37] block: vhdx write support, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 31/37] block: vhdx - break out code operations to functions, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 35/37] block: qemu-iotests for vhdx, add write test support, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 34/37] block: vhdx - update _make_test_img() to filter out vhdx options, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 23/37] block: vhdx - update log guid in header, and first write tracker, Stefan Hajnoczi, 2013/11/08
- [Qemu-devel] [PULL v2 19/37] block: vhdx - add header update capability., Stefan Hajnoczi, 2013/11/08