connection: Fix an LSM label memory leak on an error handling path
authorPhilip Withnall <withnall@endlessm.com>
Tue, 31 Jan 2017 10:04:49 +0000 (10:04 +0000)
committerSimon McVittie <smcv@debian.org>
Wed, 1 Feb 2017 18:59:34 +0000 (18:59 +0000)
This is almost certainly not going to make a difference, as it’s on the
OOM handling path; but the fewer leaks the better.

Coverity ID: 141058

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99612
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
bus/connection.c

index dd02ccd..5144218 100644 (file)
@@ -584,7 +584,7 @@ cache_peer_loginfo_string (BusConnectionData *d,
   DBusString loginfo_buf;
   unsigned long uid;
   unsigned long pid;
-  char *windows_sid, *security_label;
+  char *windows_sid = NULL, *security_label = NULL;
   dbus_bool_t prev_added;
 
   if (!_dbus_string_init (&loginfo_buf))
@@ -630,6 +630,7 @@ cache_peer_loginfo_string (BusConnectionData *d,
       did_append = _dbus_string_append_printf (&loginfo_buf,
                                                "sid=\"%s\"", windows_sid);
       dbus_free (windows_sid);
+      windows_sid = NULL;
       if (!did_append)
         goto oom;
       else
@@ -649,6 +650,7 @@ cache_peer_loginfo_string (BusConnectionData *d,
       did_append = _dbus_string_append_printf (&loginfo_buf,
                                                "label=\"%s\"", security_label);
       dbus_free (security_label);
+      security_label = NULL;
       if (!did_append)
         goto oom;
       else
@@ -663,6 +665,11 @@ cache_peer_loginfo_string (BusConnectionData *d,
   return TRUE;
 oom:
    _dbus_string_free (&loginfo_buf);
+   if (security_label != NULL)
+     dbus_free (security_label);
+   if (windows_sid != NULL)
+     dbus_free (windows_sid);
+
    return FALSE;
 }