From patchwork Wed Jan 30 10:24:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 216891 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 7A0922C0097 for ; Wed, 30 Jan 2013 23:23:00 +1100 (EST) Received: from localhost ([::1]:35739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Wgs-00065p-3a for incoming@patchwork.ozlabs.org; Wed, 30 Jan 2013 07:22:58 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Ur4-0002ci-9b for qemu-devel@nongnu.org; Wed, 30 Jan 2013 05:25:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U0Ur0-0003pY-Co for qemu-devel@nongnu.org; Wed, 30 Jan 2013 05:25:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46984) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U0Ur0-0003pJ-3T for qemu-devel@nongnu.org; Wed, 30 Jan 2013 05:25:18 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0UAPH5q006829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 30 Jan 2013 05:25:17 -0500 Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0UAPG6a027919; Wed, 30 Jan 2013 05:25:17 -0500 From: Stefan Hajnoczi To: Date: Wed, 30 Jan 2013 11:24:24 +0100 Message-Id: <1359541470-30775-17-git-send-email-stefanha@redhat.com> In-Reply-To: <1359541470-30775-1-git-send-email-stefanha@redhat.com> References: <1359541470-30775-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Markus Armbruster , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 12/18] qemu-log: Plug trivial memory leak in cpu_set_log_filename() 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 From: Markus Armbruster Signed-off-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- qemu-log.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/qemu-log.c b/qemu-log.c index 64a1b88..30c9ab0 100644 --- a/qemu-log.c +++ b/qemu-log.c @@ -21,10 +21,12 @@ #include "qemu/log.h" #ifdef WIN32 -static const char *logfilename = "qemu.log"; +#define DEFAULT_LOGFILENAME "qemu.log" #else -static const char *logfilename = "/tmp/qemu.log"; +#define DEFAULT_LOGFILENAME "/tmp/qemu.log" #endif + +static char *logfilename; FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; @@ -54,11 +56,13 @@ void qemu_log_mask(int mask, const char *fmt, ...) /* enable or disable low levels log */ void qemu_set_log(int log_flags, bool use_own_buffers) { + const char *fname = logfilename ?: DEFAULT_LOGFILENAME; + qemu_loglevel = log_flags; if (qemu_loglevel && !qemu_logfile) { - qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); + qemu_logfile = fopen(fname, log_append ? "a" : "w"); if (!qemu_logfile) { - perror(logfilename); + perror(fname); _exit(1); } /* must avoid mmap() usage of glibc by setting a buffer "by hand" */ @@ -84,6 +88,7 @@ void qemu_set_log(int log_flags, bool use_own_buffers) void cpu_set_log_filename(const char *filename) { + g_free(logfilename); logfilename = g_strdup(filename); if (qemu_logfile) { fclose(qemu_logfile);