From patchwork Fri Apr 6 13:48:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 151241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DA384B7085 for ; Sat, 7 Apr 2012 04:27:29 +1000 (EST) Received: from localhost ([::1]:55810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SG9Xg-0001TP-8e for incoming@patchwork.ozlabs.org; Fri, 06 Apr 2012 09:49:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SG9XU-0001Sr-SO for qemu-devel@nongnu.org; Fri, 06 Apr 2012 09:49:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SG9XK-0004oU-Gt for qemu-devel@nongnu.org; Fri, 06 Apr 2012 09:49:20 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:49672) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SG9XK-0004m6-7j for qemu-devel@nongnu.org; Fri, 06 Apr 2012 09:49:10 -0400 Received: by pbcuo5 with SMTP id uo5so2997631pbc.4 for ; Fri, 06 Apr 2012 06:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer; bh=Rd8CR5VMOfD71isabEq2oqpDMv4C2usmh5tpdOfEWec=; b=yhzipYjHmQ6LNRZVzbuAWiBjTu1PnrurUWm+fVao4hn6CZVdFXSIkLuBpSposGJ2U+ yL6WvUn8qta9Go+Jod2DVYVuRt6Mk1qkIyi0jPzY62ETLY6aokb+TQbAeNTe3wuUyuJ9 YMHFZUITVCz/Z5sP0POgAgJJHSKczBWORJg6cyunDI2lM27bZiWRysi+PFsAZ7jvqLDl kA4bgXpRcPdhipQN5HkysNQdNfOrNLo2TPXk2ErMwgiOTzGKBZ3x9UNSrqeZ/GR7tLxO 0SYg7ZEeoH5pppNZwP0FnbcsUeNNpZlzmfAQR7nXGSqqnWORjvFyJZKMeAi3GF6WSiDd ViUw== Received: by 10.68.201.65 with SMTP id jy1mr16083280pbc.5.1333720138670; Fri, 06 Apr 2012 06:48:58 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id s10sm6349519pbp.14.2012.04.06.06.48.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 Apr 2012 06:48:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 6 Apr 2012 15:48:45 +0200 Message-Id: <1333720125-32485-1-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.9.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH] scsi: fix memory leak X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org scsibus_get_dev_path is leaking id if it is not NULL. Fix it. Reported-by: Laszlo Ersek Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 8e76c5d..216b51f 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1430,15 +1430,18 @@ static char *scsibus_get_dev_path(DeviceState *dev) SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev); DeviceState *hba = dev->parent_bus->parent; char *id = NULL; + char *path; if (hba && hba->parent_bus && hba->parent_bus->info->get_dev_path) { id = hba->parent_bus->info->get_dev_path(hba); } if (id) { - return g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->lun); + path = g_strdup_printf("%s/%d:%d:%d", id, d->channel, d->id, d->lun); } else { - return g_strdup_printf("%d:%d:%d", d->channel, d->id, d->lun); + path = g_strdup_printf("%d:%d:%d", d->channel, d->id, d->lun); } + free(id); + return path; } static char *scsibus_get_fw_dev_path(DeviceState *dev)