aboutsummaryrefslogtreecommitdiff
path: root/qemu-log.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2013-01-22 11:08:03 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2013-01-30 11:14:46 +0100
commit40a50b0a73d185c85cf62023f07e3091861081bb (patch)
tree2f556e6f3e0e2deb88e159b487a1d889ea5ef6c1 /qemu-log.c
parent636e0f27c6675839dc43d4c7613dfefc222234eb (diff)
downloadqemu-40a50b0a73d185c85cf62023f07e3091861081bb.zip
qemu-40a50b0a73d185c85cf62023f07e3091861081bb.tar.gz
qemu-40a50b0a73d185c85cf62023f07e3091861081bb.tar.bz2
qemu-log: Plug trivial memory leak in cpu_set_log_filename()
Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qemu-log.c')
-rw-r--r--qemu-log.c13
1 files 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);