Block patches

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJTjIJwAAoJEH8JsnLIjy/WVGsQALIytTnSQcYtB2R0Npw0R9pO
 Zhp1hcAN8sQKEbfA7t4lp9rmc2+JhgwQO7KI/3Dhk43/LQFLOEPtDsEINZT830QZ
 gvaHQVNLGhxhuIZG2njeJB2CEfBRjJjZ5DtA5sHAsKLcQKbA0xBCqhlCAL5gZ7/O
 Up/TOXOP396n4oIjBzUGY0WRxVYTaixpEQuk7oCh2/s3hihj3GU6PKjB8bqHd9PE
 bwaXv2gIkaHnsTyHn9QvRTci9EqNcpV1uSPGvjU7C7hDhIx30EXBC0ptY619PtYc
 nTqRkc0jU+jq2CMUbOwkKFDMN4rivYwxpWs8iOZZViFUuSWfmsMWXXTNRNybWGwa
 o6FCBwXqTYVa+a7048oDZAEGZkbiM4upzWtlztjSGEoRGgra81WQUiltUsJi+U3s
 kySVCCNdMWY5jwN3ceEuhZpQ8Uv8qpMS857TFax1tQb0RjLu2vKHf1rUuNmtAyJ1
 fPYvsXAgEozavhl63vOCo1mgZknvId9keO8p9h23HObZJhcMORNZ/eMKzK2OjMQe
 T1QmWBTBXs0ULkuv4E7CwSQ9Dr09VJnTHM5EjekhxXfu1Dq4N/6gZmcoWu49VIvg
 Ho6Xg72z+sFdJ7Y/l8oCqUKCJdmQT2GeqKEkS3QiH0nY+J26ZtGNnylm1cUQzY7Z
 3tbAuQi/mIDVF++M08CA
 =WVw4
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging

Block patches

# gpg: Signature made Mon 02 Jun 2014 14:56:00 BST using RSA key ID C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"

* remotes/kevin/tags/for-upstream:
  qemu-img: Report error even with --oformat=json
  vmdk: Fix local_err in vmdk_create
  block/raw-posix.c: Avoid nonstandard LONG_LONG_MAX
  qemu-img: Plug memory leak in convert command
  block/sheepdog: Plug memory leak in sd_snapshot_create()
  block/vvfat: Plug memory leak in read_directory()
  block/vvfat: Plug memory leak in check_directory_consistency()
  block/qapi: Plug memory leak in dump_qobject() case QTYPE_QERROR
  blockdev: Plug memory leak in drive_init()
  blockdev: Plug memory leak in blockdev_init()
  qemu-io: Don't print NULL when open without non-option arg fails
  qemu-io: Plug memory leak in open command
  qemu-io: Support multiple -o in open command
  block: Plug memory leak on brv_open_image() error path
  qcow2: Plug memory leak on qcow2_invalidate_cache() error paths
  block/vvfat: Plug memory leak in enable_write_target()
  qemu-img: Plug memory leak on block option help error path

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2014-06-02 15:27:18 +01:00
commit f72b49398f
10 changed files with 38 additions and 24 deletions

View File

@ -1228,6 +1228,7 @@ int bdrv_open_image(BlockDriverState **pbs, const char *filename,
bdref_key); bdref_key);
ret = -EINVAL; ret = -EINVAL;
} }
QDECREF(image_options);
goto done; goto done;
} }

View File

@ -475,6 +475,7 @@ static void dump_qobject(fprintf_function func_fprintf, void *f,
case QTYPE_QERROR: { case QTYPE_QERROR: {
QString *value = qerror_human((QError *)obj); QString *value = qerror_human((QError *)obj);
func_fprintf(f, "%s", qstring_get_str(value)); func_fprintf(f, "%s", qstring_get_str(value));
QDECREF(value);
break; break;
} }
case QTYPE_NONE: case QTYPE_NONE:

View File

@ -1308,6 +1308,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp)
options = qdict_clone_shallow(bs->options); options = qdict_clone_shallow(bs->options);
ret = qcow2_open(bs, options, flags, &local_err); ret = qcow2_open(bs, options, flags, &local_err);
QDECREF(options);
if (local_err) { if (local_err) {
error_setg(errp, "Could not reopen qcow2 layer: %s", error_setg(errp, "Could not reopen qcow2 layer: %s",
error_get_pretty(local_err)); error_get_pretty(local_err));
@ -1318,8 +1319,6 @@ static void qcow2_invalidate_cache(BlockDriverState *bs, Error **errp)
return; return;
} }
QDECREF(options);
if (crypt_method) { if (crypt_method) {
s->crypt_method = crypt_method; s->crypt_method = crypt_method;
memcpy(&s->aes_encrypt_key, &aes_encrypt_key, sizeof(aes_encrypt_key)); memcpy(&s->aes_encrypt_key, &aes_encrypt_key, sizeof(aes_encrypt_key));

View File

@ -1192,7 +1192,7 @@ again:
if (size == 0) if (size == 0)
#endif #endif
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
size = LONG_LONG_MAX; size = LLONG_MAX;
#else #else
size = lseek(fd, 0LL, SEEK_END); size = lseek(fd, 0LL, SEEK_END);
#endif #endif

View File

@ -2176,6 +2176,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag)); strncpy(s->inode.tag, sn_info->name, sizeof(s->inode.tag));
/* we don't need to update entire object */ /* we don't need to update entire object */
datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id); datalen = SD_INODE_SIZE - sizeof(s->inode.data_vdi_id);
inode = g_malloc(datalen);
/* refresh inode. */ /* refresh inode. */
fd = connect_to_sdog(s, &local_err); fd = connect_to_sdog(s, &local_err);
@ -2202,8 +2203,6 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
goto cleanup; goto cleanup;
} }
inode = (SheepdogInode *)g_malloc(datalen);
ret = read_object(fd, (char *)inode, vid_to_vdi_oid(new_vid), ret = read_object(fd, (char *)inode, vid_to_vdi_oid(new_vid),
s->inode.nr_copies, datalen, 0, s->cache_flags); s->inode.nr_copies, datalen, 0, s->cache_flags);
@ -2217,6 +2216,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
s->inode.name, s->inode.snap_id, s->inode.vdi_id); s->inode.name, s->inode.snap_id, s->inode.vdi_id);
cleanup: cleanup:
g_free(inode);
closesocket(fd); closesocket(fd);
return ret; return ret;
} }

View File

@ -1534,7 +1534,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
int ret, i; int ret, i;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
VMDK4Header header; VMDK4Header header;
Error *local_err; Error *local_err = NULL;
uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count; uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count;
uint32_t *gd_buf = NULL; uint32_t *gd_buf = NULL;
int gd_buf_size; int gd_buf_size;
@ -1700,7 +1700,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
{ {
int idx = 0; int idx = 0;
BlockDriverState *new_bs = NULL; BlockDriverState *new_bs = NULL;
Error *local_err; Error *local_err = NULL;
char *desc = NULL; char *desc = NULL;
int64_t total_size = 0, filesize; int64_t total_size = 0, filesize;
const char *adapter_type = NULL; const char *adapter_type = NULL;
@ -1881,7 +1881,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
} else { } else {
ret = bdrv_create_file(filename, options, &local_err); ret = bdrv_create_file(filename, options, &local_err);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not create image file"); error_propagate(errp, local_err);
goto exit; goto exit;
} }
} }
@ -1889,7 +1889,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options,
ret = bdrv_open(&new_bs, filename, NULL, NULL, ret = bdrv_open(&new_bs, filename, NULL, NULL,
BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err); BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write description"); error_propagate(errp, local_err);
goto exit; goto exit;
} }
ret = bdrv_pwrite(new_bs, desc_offset, desc, desc_len); ret = bdrv_pwrite(new_bs, desc_offset, desc, desc_len);

View File

@ -787,7 +787,9 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
s->current_mapping->path=buffer; s->current_mapping->path=buffer;
s->current_mapping->read_only = s->current_mapping->read_only =
(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0; (st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0;
} } else {
g_free(buffer);
}
} }
closedir(dir); closedir(dir);
@ -1866,7 +1868,7 @@ static int check_directory_consistency(BDRVVVFATState *s,
if (s->used_clusters[cluster_num] & USED_ANY) { if (s->used_clusters[cluster_num] & USED_ANY) {
fprintf(stderr, "cluster %d used more than once\n", (int)cluster_num); fprintf(stderr, "cluster %d used more than once\n", (int)cluster_num);
return 0; goto fail;
} }
s->used_clusters[cluster_num] = USED_DIRECTORY; s->used_clusters[cluster_num] = USED_DIRECTORY;
@ -2929,6 +2931,7 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:"); set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, errp); ret = bdrv_create(bdrv_qcow, s->qcow_filename, options, errp);
free_option_parameters(options);
if (ret < 0) { if (ret < 0) {
goto err; goto err;
} }

View File

@ -351,7 +351,7 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error); opts = qemu_opts_create(&qemu_common_drive_opts, id, 1, &error);
if (error) { if (error) {
error_propagate(errp, error); error_propagate(errp, error);
return NULL; goto err_no_opts;
} }
qemu_opts_absorb_qdict(opts, bs_opts, &error); qemu_opts_absorb_qdict(opts, bs_opts, &error);
@ -564,8 +564,9 @@ bdrv_new_err:
g_free(dinfo->id); g_free(dinfo->id);
g_free(dinfo); g_free(dinfo);
early_err: early_err:
QDECREF(bs_opts);
qemu_opts_del(opts); qemu_opts_del(opts);
err_no_opts:
QDECREF(bs_opts);
return NULL; return NULL;
} }
@ -939,6 +940,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
/* Actual block device init: Functionality shared with blockdev-add */ /* Actual block device init: Functionality shared with blockdev-add */
dinfo = blockdev_init(filename, bs_opts, &local_err); dinfo = blockdev_init(filename, bs_opts, &local_err);
bs_opts = NULL;
if (dinfo == NULL) { if (dinfo == NULL) {
if (local_err) { if (local_err) {
error_report("%s", error_get_pretty(local_err)); error_report("%s", error_get_pretty(local_err));
@ -976,6 +978,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
fail: fail:
qemu_opts_del(legacy_opts); qemu_opts_del(legacy_opts);
QDECREF(bs_opts);
return dinfo; return dinfo;
} }

View File

@ -287,6 +287,7 @@ static int print_block_option_help(const char *filename, const char *fmt)
proto_drv = bdrv_find_protocol(filename, true); proto_drv = bdrv_find_protocol(filename, true);
if (!proto_drv) { if (!proto_drv) {
error_report("Unknown protocol '%s'", filename); error_report("Unknown protocol '%s'", filename);
free_option_parameters(create_options);
return 1; return 1;
} }
create_options = append_option_parameters(create_options, create_options = append_option_parameters(create_options,
@ -662,9 +663,7 @@ static int img_check(int argc, char **argv)
ret = collect_image_check(bs, check, filename, fmt, fix); ret = collect_image_check(bs, check, filename, fmt, fix);
if (ret == -ENOTSUP) { if (ret == -ENOTSUP) {
if (output_format == OFORMAT_HUMAN) { error_report("This image format does not support checks");
error_report("This image format does not support checks");
}
ret = 63; ret = 63;
goto fail; goto fail;
} }
@ -1454,7 +1453,7 @@ static int img_convert(int argc, char **argv)
ret = bdrv_parse_cache_flags(cache, &flags); ret = bdrv_parse_cache_flags(cache, &flags);
if (ret < 0) { if (ret < 0) {
error_report("Invalid cache option: %s", cache); error_report("Invalid cache option: %s", cache);
return -1; goto out;
} }
out_bs = bdrv_new_open("target", out_filename, out_fmt, flags, true, quiet); out_bs = bdrv_new_open("target", out_filename, out_fmt, flags, true, quiet);

View File

@ -54,6 +54,7 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
if (qemuio_bs) { if (qemuio_bs) {
fprintf(stderr, "file open already, try 'help close'\n"); fprintf(stderr, "file open already, try 'help close'\n");
QDECREF(opts);
return 1; return 1;
} }
@ -61,7 +62,8 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
if (bdrv_open(&qemuio_bs, name, NULL, opts, flags | BDRV_O_PROTOCOL, if (bdrv_open(&qemuio_bs, name, NULL, opts, flags | BDRV_O_PROTOCOL,
NULL, &local_err)) NULL, &local_err))
{ {
fprintf(stderr, "%s: can't open device %s: %s\n", progname, name, fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
name ? " device " : "", name ?: "",
error_get_pretty(local_err)); error_get_pretty(local_err));
error_free(local_err); error_free(local_err);
return 1; return 1;
@ -72,7 +74,8 @@ static int openfile(char *name, int flags, int growable, QDict *opts)
if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err) if (bdrv_open(&qemuio_bs, name, NULL, opts, flags, NULL, &local_err)
< 0) < 0)
{ {
fprintf(stderr, "%s: can't open device %s: %s\n", progname, name, fprintf(stderr, "%s: can't open%s%s: %s\n", progname,
name ? " device " : "", name ?: "",
error_get_pretty(local_err)); error_get_pretty(local_err));
error_free(local_err); error_free(local_err);
bdrv_unref(qemuio_bs); bdrv_unref(qemuio_bs);
@ -118,6 +121,7 @@ static const cmdinfo_t open_cmd = {
static QemuOptsList empty_opts = { static QemuOptsList empty_opts = {
.name = "drive", .name = "drive",
.merge_lists = true,
.head = QTAILQ_HEAD_INITIALIZER(empty_opts.head), .head = QTAILQ_HEAD_INITIALIZER(empty_opts.head),
.desc = { .desc = {
/* no elements => accept any params */ /* no elements => accept any params */
@ -132,7 +136,7 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
int growable = 0; int growable = 0;
int c; int c;
QemuOpts *qopts; QemuOpts *qopts;
QDict *opts = NULL; QDict *opts;
while ((c = getopt(argc, argv, "snrgo:")) != EOF) { while ((c = getopt(argc, argv, "snrgo:")) != EOF) {
switch (c) { switch (c) {
@ -149,15 +153,14 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
growable = 1; growable = 1;
break; break;
case 'o': case 'o':
qopts = qemu_opts_parse(&empty_opts, optarg, 0); if (!qemu_opts_parse(&empty_opts, optarg, 0)) {
if (qopts == NULL) {
printf("could not parse option list -- %s\n", optarg); printf("could not parse option list -- %s\n", optarg);
qemu_opts_reset(&empty_opts);
return 0; return 0;
} }
opts = qemu_opts_to_qdict(qopts, opts);
qemu_opts_del(qopts);
break; break;
default: default:
qemu_opts_reset(&empty_opts);
return qemuio_command_usage(&open_cmd); return qemuio_command_usage(&open_cmd);
} }
} }
@ -166,11 +169,16 @@ static int open_f(BlockDriverState *bs, int argc, char **argv)
flags |= BDRV_O_RDWR; flags |= BDRV_O_RDWR;
} }
qopts = qemu_opts_find(&empty_opts, NULL);
opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
qemu_opts_reset(&empty_opts);
if (optind == argc - 1) { if (optind == argc - 1) {
return openfile(argv[optind], flags, growable, opts); return openfile(argv[optind], flags, growable, opts);
} else if (optind == argc) { } else if (optind == argc) {
return openfile(NULL, flags, growable, opts); return openfile(NULL, flags, growable, opts);
} else { } else {
QDECREF(opts);
return qemuio_command_usage(&open_cmd); return qemuio_command_usage(&open_cmd);
} }
} }