From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uvsny-0002IM-4v for qemu-devel@nongnu.org; Sun, 07 Jul 2013 13:31:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uvsnx-0005Gq-10 for qemu-devel@nongnu.org; Sun, 07 Jul 2013 13:31:22 -0400 Received: from cantor2.suse.de ([195.135.220.15]:56732 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uvsnw-0005Gd-NC for qemu-devel@nongnu.org; Sun, 07 Jul 2013 13:31:20 -0400 Message-ID: <51D9A5E2.1080207@suse.de> Date: Sun, 07 Jul 2013 19:31:14 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1372929678-14341-1-git-send-email-mohan@in.ibm.com> <87vc4m9tm6.fsf@linux.vnet.ibm.com> In-Reply-To: <87vc4m9tm6.fsf@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/1] hw/9pfs: Fix memory leak in error path List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Aneesh Kumar K.V" Cc: Anthony Liguori , "M. Mohan Kumar" , qemu-devel@nongnu.org Am 07.07.2013 19:18, schrieb Aneesh Kumar K.V: > "M. Mohan Kumar" writes: >=20 >> From: "M. Mohan Kumar" >> >> Fix few more memory leaks in virtio-9p-device.c detected using valgrin= d. >> >> Signed-off-by: M. Mohan Kumar >> --- >> hw/9pfs/virtio-9p-device.c | 26 +++++++++++++++++--------- >> 1 file changed, 17 insertions(+), 9 deletions(-) >> >> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c >> index dc6f4e4..35e2af4 100644 >> --- a/hw/9pfs/virtio-9p-device.c >> +++ b/hw/9pfs/virtio-9p-device.c >> @@ -68,14 +68,14 @@ static int virtio_9p_device_init(VirtIODevice *vde= v) >> fprintf(stderr, "Virtio-9p device couldn't find fsdev with th= e " >> "id =3D %s\n", >> s->fsconf.fsdev_id ? s->fsconf.fsdev_id : "NULL"); >> - return -1; >> + goto out; >> } >> >> if (!s->fsconf.tag) { >> /* we haven't specified a mount_tag */ >> fprintf(stderr, "fsdev with id %s needs mount_tag arguments\n= ", >> s->fsconf.fsdev_id); >> - return -1; >> + goto out; >> } >> >> s->ctx.export_flags =3D fse->export_flags; >> @@ -85,10 +85,10 @@ static int virtio_9p_device_init(VirtIODevice *vde= v) >> if (len > MAX_TAG_LEN - 1) { >> fprintf(stderr, "mount tag '%s' (%d bytes) is longer than " >> "maximum (%d bytes)", s->fsconf.tag, len, MAX_TAG_LEN= - 1); >> - return -1; >> + goto out; >> } >> >> - s->tag =3D strdup(s->fsconf.tag); >> + s->tag =3D g_strdup(s->fsconf.tag); >> s->ctx.uid =3D -1; >> >> s->ops =3D fse->ops; >> @@ -99,11 +99,11 @@ static int virtio_9p_device_init(VirtIODevice *vde= v) >> if (s->ops->init(&s->ctx) < 0) { >> fprintf(stderr, "Virtio-9p Failed to initialize fs-driver wit= h id:%s" >> " and export path:%s\n", s->fsconf.fsdev_id, s->ctx.f= s_root); >> - return -1; >> + goto out; >> } >> if (v9fs_init_worker_threads() < 0) { >> fprintf(stderr, "worker thread initialization failed\n"); >> - return -1; >> + goto out; >> } >> >> /* >> @@ -115,18 +115,26 @@ static int virtio_9p_device_init(VirtIODevice *v= dev) >> if (s->ops->name_to_path(&s->ctx, NULL, "/", &path) < 0) { >> fprintf(stderr, >> "error in converting name to path %s", strerror(errno= )); >> - return -1; >> + goto out; >> } >> if (s->ops->lstat(&s->ctx, &path, &stat)) { >> fprintf(stderr, "share path %s does not exist\n", fse->path); >> - return -1; >> + goto out; >> } else if (!S_ISDIR(stat.st_mode)) { >> fprintf(stderr, "share path %s is not a directory\n", fse->pa= th); >> - return -1; >> + goto out; >> } >> v9fs_path_free(&path); >> >> return 0; >> +out: >> + g_free(s->ctx.fs_root); >> + g_free(s->tag); >> + virtio_cleanup(vdev); >> + v9fs_path_free(&path); >> + >> + return -1; >> + >> } >> >=20 > The error path will result in qemu terminating right ? Do we care about > g_free in those case ? See my patches on the list converting VirtioDevices to QOM realize: Realization grows an Error **errp argument for reporting errors, and it's up to the caller to decide whether to continue (think device_add) or terminate (-device). Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg