From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnMvI-0001DZ-N3 for qemu-devel@nongnu.org; Fri, 23 Sep 2016 05:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnMvG-0002Ax-L5 for qemu-devel@nongnu.org; Fri, 23 Sep 2016 05:37:35 -0400 Date: Fri, 23 Sep 2016 11:37:27 +0200 From: Kevin Wolf Message-ID: <20160923093727.GB5436@noname.redhat.com> References: <1474558931-8968-1-git-send-email-kwolf@redhat.com> <1474558931-8968-2-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="UugvWAfsgieZRqgk" Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 1/3] block: Add '-blockdev' command line option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-block@nongnu.org, armbru@redhat.com, mreitz@redhat.com, berrange@redhat.com, qemu-devel@nongnu.org --UugvWAfsgieZRqgk Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 22.09.2016 um 20:45 hat Eric Blake geschrieben: > On 09/22/2016 10:42 AM, Kevin Wolf wrote: > > This is an option that is directly mapped to the blockdev-add QMP > > command. It works more or less like -drive, except that it doesn't > > create a BlockBackend and doesn't support legacy options. > >=20 > > This patch adds minimal documentation, the next patches will improve it. > >=20 > > Signed-off-by: Kevin Wolf > > --- > > blockdev.c | 12 +++++++++++ > > include/sysemu/sysemu.h | 1 + > > qemu-options.hx | 12 +++++++++++ > > vl.c | 57 +++++++++++++++++++++++++++++++++++++++++= ++++++++ > > 4 files changed, 82 insertions(+) > >=20 >=20 > > +static int blockdev_init_func(void *opaque, QemuOpts *opts, Error **er= rp) > > +{ > > + BlockdevOptions *options; >=20 > Uninitialized... Oops, good catch. Thanks. > > + Visitor *v =3D NULL; > > + Error *local_err =3D NULL; > > + > > + QDict *opts_dict =3D qemu_opts_to_qdict(opts, NULL); > > + QObject *crumpled =3D qdict_crumple(opts_dict, true, &local_err); > > + if (local_err) { > > + goto fail; >=20 > ...can fail without initializing it... >=20 > > + } > > + > > + v =3D qobject_string_input_visitor_new(crumpled); > > + visit_type_BlockdevOptions(v, NULL, &options, &local_err); >=20 > This is so deceptively simple! It's taken us months to get to this > point, but I love the end result. However, >=20 > ...this initializes options, and may result in malloc'd memory... >=20 > > + if (local_err) { > > + goto fail; > > + } > > + visit_complete(v, opts); > > + > > + qmp_blockdev_add(options, &local_err); > > + if (local_err) { > > + goto fail; > > + } > > + > > +fail: > > + QDECREF(opts_dict); > > + qobject_decref(crumpled); > > + > > + visit_free(v); > > + > > + v =3D qapi_dealloc_visitor_new(); > > + visit_type_BlockdevOptions(v, NULL, &options, NULL); >=20 > ...this can call the dealloc visitor on uninitialized memory, if we took > the first goto... >=20 > > + visit_free(v); > > + > > + if (local_err) { > > + error_propagate(errp, local_err); > > + } > > + return !!local_err; >=20 > ...and this leaks options if you did not take the first goto. >=20 > You want NULL initialization, and a qapi_free_BlockdevOptions(options) > in here. Yes, I'll add the NULL initialisation. I don't think you're right about the leak, the dealloc visitor takes care of deallocating the top level object as well. However, it's true that qapi_free_BlockdevOptions() already has the dealloc visitor code internally, so instead of open-coding it here, I can replace (rather than complement) the above code with a call to it. Kevin --UugvWAfsgieZRqgk Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJX5PfXAAoJEH8JsnLIjy/WSw8QAKNU6vmduHDY6y4Z6doVbxtS X4r96e6JEV9ZRPlR4++5tafLxDuDTYnIEO0RoNSY8Ra//nhvac6icJmqBxW7vUtG oO91oaD5KLG6EtOAZCoCdsBkp8fca5digSbpIqQaSV++dljTzlD1NFa+4nwD/aMN ZHmrLQft+HglmJNJqAgGEhIWoQ5D7KQey/BifZJDCi7btdz/zbZgEM3UKt1Dwrct OT6dwcsRmsoDcBAaxQLgryz8S+ai4msaa6IbXCTpAD9REXWVB+fDOU3iTqhV4Ima txgLu77Av2kZumN99XmxhggA9v4wKU5KmxbURWJWV0w4L422pLOWU7Kq+jDiIZNs tQWL2N8agp689nEVis3byXugV38H+lZQqL4UwkwEqKyvcUNy6GJGyQJMzVeJD5X1 OO/0VoxgeabzPcmyTFG6SJu0f7GqsSe+MGy83v2s7dWuOFzc8TwbEeHsx3BvlFSg dMDbRtq1WgafdxhOhG5OLzH/HW1JmmSXCeMFSRP+RWW9xEoZUnWN/EPPicnXepzh uEIMN2pgDwvDSHm7gYLZqHzAKstrpqjPmhg2EP2fBFhN5FX5GGx36QNAx0+vSald znSjs+W78xN0YHGHN68f5M3X3NyIv9hxNf1K/jkAfBOgpJK3SCk6wX5uj0LB7O4N IcqloyOsZse9AseLiytC =GUQr -----END PGP SIGNATURE----- --UugvWAfsgieZRqgk--