Received: from eggs.gnu.org ([140.186.70.92]:58013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOuZ1-0006pD-J4 for qemu-devel@nongnu.org; Tue, 24 May 2011 12:34:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOuZ0-00039v-FL for qemu-devel@nongnu.org; Tue, 24 May 2011 12:34:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOuZ0-00039o-8Y for qemu-devel@nongnu.org; Tue, 24 May 2011 12:34:34 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4OGYWIn015038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 24 May 2011 12:34:33 -0400 Date: Tue, 24 May 2011 19:34:26 +0300 From: Alon Levy Message-ID: <20110524163426.GN14048@playa.tlv.redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH] usb-ccid: Plug memory leak on qdev exit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org On Tue, May 24, 2011 at 06:09:10PM +0200, Markus Armbruster wrote: > ccid_initfn() allocates CCIDBus dynamically, but there is no exit > callback to free it. > > Fix by getting rid of the allocation. > > Signed-off-by: Markus Armbruster Tested-by: Alon Levy > --- > hw/usb-ccid.c | 28 ++++++++-------------------- > 1 files changed, 8 insertions(+), 20 deletions(-) > > diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c > index 079b4a2..ba2576b 100644 > --- a/hw/usb-ccid.c > +++ b/hw/usb-ccid.c > @@ -255,17 +255,18 @@ enum { > MIGRATION_MIGRATED, > }; > > -typedef struct CCIDBus CCIDBus; > -typedef struct USBCCIDState USBCCIDState; > +typedef struct CCIDBus { > + BusState qbus; > +} CCIDBus; > > #define MAX_PROTOCOL_SIZE 7 > > /* > * powered - defaults to true, changed by PowerOn/PowerOff messages > */ > -struct USBCCIDState { > +typedef struct USBCCIDState { > USBDevice dev; > - CCIDBus *bus; > + CCIDBus bus; > CCIDCardState *card; > CCIDCardInfo *cardinfo; /* caching the info pointer */ > BulkIn bulk_in_pending[BULK_IN_PENDING_NUM]; /* circular */ > @@ -293,7 +294,7 @@ struct USBCCIDState { > uint8_t powered; > uint8_t notify_slot_change; > uint8_t debug; > -}; > +} USBCCIDState; > > /* > * CCID Spec chapter 4: CCID uses a standard device descriptor per Chapter 9, > @@ -1113,10 +1114,6 @@ static void ccid_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) > } > } > > -struct CCIDBus { > - BusState qbus; > -}; > - > static struct BusInfo ccid_bus_info = { > .name = "ccid-bus", > .size = sizeof(CCIDBus), > @@ -1127,16 +1124,6 @@ static struct BusInfo ccid_bus_info = { > } > }; > > -static CCIDBus *ccid_bus_new(DeviceState *dev) > -{ > - CCIDBus *bus; > - > - bus = FROM_QBUS(CCIDBus, qbus_create(&ccid_bus_info, dev, NULL)); > - bus->qbus.allow_hotplug = 1; > - > - return bus; > -} > - > void ccid_card_send_apdu_to_guest(CCIDCardState *card, > uint8_t *apdu, uint32_t len) > { > @@ -1276,7 +1263,8 @@ static int ccid_initfn(USBDevice *dev) > { > USBCCIDState *s = DO_UPCAST(USBCCIDState, dev, dev); > > - s->bus = ccid_bus_new(&dev->qdev); > + qbus_create_inplace(&s->bus.qbus, &ccid_bus_info, &dev->qdev, NULL); > + s->bus.qbus.allow_hotplug = 1; > s->card = NULL; > s->cardinfo = NULL; > s->migration_state = MIGRATION_NONE; > -- > 1.7.2.3 >