From 6d6d4053d1b8c7d0cf672a989aee6f6ecc9ef5f6 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 9 Nov 2015 13:32:02 +0100 Subject: [PATCH 1/2] Fix memory leak in _dbus_win_set_error_from_win_error(). There is not need to make a local (leaked) copy of the message, because dbus_set_error() already makes a copy of its parameters. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721 --- dbus/dbus-sysdeps-win.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index e626cc6..287816d 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -2377,6 +2377,8 @@ _dbus_delete_file (const DBusString *filename, # define BACKTRACES #endif +#undef BACKTRACES + #ifdef BACKTRACES /* * Backtrace Generator @@ -3602,6 +3604,9 @@ _dbus_win_set_error_from_win_error (DBusError *error, { char *msg; + if (!error) + return; + /* As we want the English message, use the A API */ FormatMessageA (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | @@ -3610,13 +3615,8 @@ _dbus_win_set_error_from_win_error (DBusError *error, (LPSTR) &msg, 0, NULL); if (msg) { - char *msg_copy; - - msg_copy = dbus_malloc (strlen (msg)); - strcpy (msg_copy, msg); + dbus_set_error (error, "win32.error", "%s", msg); LocalFree (msg); - - dbus_set_error (error, "win32.error", "%s", msg_copy); } else dbus_set_error (error, "win32.error", "Unknown error code %d or FormatMessage failed", code); -- 1.8.4.5