dbus_message_demarshal: Set error if we can't allocate the loader
authorSimon McVittie <smcv@collabora.com>
Mon, 27 Nov 2017 19:13:25 +0000 (19:13 +0000)
committerSimon McVittie <smcv@collabora.com>
Wed, 5 Oct 2022 09:46:55 +0000 (10:46 +0100)
Backported from 1.13.0. Previously this was fixed in the dbus-1.14 branch
but unfixed in the dbus-1.12 branch, but we need it fixed in dbus-1.12
if we want the additional test coverage for dbus#413 to pass.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100317
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit ecbcffae19ff1b811fc7d0d602458c0f00dd6771)

dbus/dbus-message.c

index 84d8c0c..34b56f1 100644 (file)
@@ -5093,7 +5093,7 @@ dbus_message_demarshal (const char *str,
                         int         len,
                         DBusError  *error)
 {
-  DBusMessageLoader *loader;
+  DBusMessageLoader *loader = NULL;
   DBusString *buffer;
   DBusMessage *msg;
 
@@ -5102,7 +5102,7 @@ dbus_message_demarshal (const char *str,
   loader = _dbus_message_loader_new ();
 
   if (loader == NULL)
-    return NULL;
+    goto fail_oom;
 
   _dbus_message_loader_get_buffer (loader, &buffer, NULL, NULL);
 
@@ -5133,7 +5133,10 @@ dbus_message_demarshal (const char *str,
 
  fail_oom:
   _DBUS_SET_OOM (error);
-  _dbus_message_loader_unref (loader);
+
+  if (loader != NULL)
+    _dbus_message_loader_unref (loader);
+
   return NULL;
 }