[libnet-dbus-perl] 94/335: Incorporate fix from Emmanuele Bassi to ensure memory is not leaked when throwing errors

Intrigeri intrigeri at moszumanska.debian.org
Sat Mar 21 01:07:32 UTC 2015


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to branch experimental
in repository libnet-dbus-perl.

commit 8c334b429f34bccb97df69ac49678ca5f3b1a997
Author: Daniel P. Berrange <dan at berrange.com>
Date:   Fri Sep 2 13:09:21 2005 +0000

    Incorporate fix from  Emmanuele Bassi to ensure memory is not leaked when throwing errors
---
 AUTHORS |  7 ++++---
 DBus.xs | 55 ++++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 9e816ec..1a0f57a 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -3,11 +3,12 @@
 
 Net::DBus is written by 
 
-    Daniel Berrange <dan at berrange.com>
+    Daniel Berrange <dan-at-berrange-dot-com>
 
-With patches / contributions greatfully received from
+With patches & contributions gratefully received from
 
-    Carlos Garnacho <carlosg at gnome.org>
+    Carlos Garnacho <carlosg-at-gnome-dot-org>
+    Emmanuele Bassi <ebassi-at-gmail-dot-com>
 
     [...send patches to get your name here!]
 
diff --git a/DBus.xs b/DBus.xs
index 5c3b38f..327a445 100644
--- a/DBus.xs
+++ b/DBus.xs
@@ -302,6 +302,41 @@ DBusObjectPathVTable _path_callback_vtable = {
         NULL
 };
 
+SV *
+_sv_from_error (DBusError *error)
+{
+    HV *hv;
+
+    if (!error) {
+      warn ("error is NULL");
+      return &PL_sv_undef;
+    }
+    
+    if (!dbus_error_is_set (error)) {
+      warn ("error is unset");
+      return &PL_sv_undef;
+    }
+    
+    hv = newHV ();
+    
+    /* map DBusError attributes to hash keys */
+    hv_store (hv, "name", 4, newSVpv (error->name, 0), 0);
+    hv_store (hv, "message", 7, newSVpv (error->message, 0), 0);
+    
+    return sv_bless (newRV_noinc ((SV*) hv), gv_stashpv ("Net::DBus::Error", TRUE));
+}
+
+void
+_croak_error (DBusError *error)
+{
+    sv_setsv (ERRSV, _sv_from_error (error));
+    
+    /* croak does not return, so we free this now to avoid leaking */
+    dbus_error_free (error);
+    
+    croak (Nullch);
+}
+
 void
 _populate_constant(HV *href, char *name, int val)
 {
@@ -373,9 +408,7 @@ _open(address)
         dbus_error_init(&error);
         con = dbus_connection_open(address, &error);
         if (!con) {
-          // XXX fixme
-          //dbus_error_free(&error);
-          croak(error.message);
+          _croak_error (&error);
         }
         RETVAL = con;
     OUTPUT:
@@ -434,7 +467,7 @@ _send_with_reply_and_block(con, msg, timeout)
     CODE:
         dbus_error_init(&error);
         if (!(reply = dbus_connection_send_with_reply_and_block(con, msg, timeout, &error))) {
-          croak(error.message);
+          _croak_error(&error);
         }
         PD_DEBUG("Create msg reply %x\n", reply);
         PD_DEBUG("  Type %d\n", dbus_message_get_type(reply));
@@ -524,7 +557,7 @@ dbus_bus_register(con)
     CODE:
         dbus_error_init(&error);
         if (!(reply = dbus_bus_register(con, &error))) {
-          croak(error.message);
+          _croak_error(&error);
         }
         RETVAL = reply;
 
@@ -539,7 +572,7 @@ dbus_bus_add_match(con, rule)
 	PD_DEBUG("Adding match %s\n", rule);
         dbus_bus_add_match(con, rule, &error);
 	if (dbus_error_is_set(&error)) {
-	  croak("cannot add match %s", error.message);
+	  _croak_error(&error);
  	}
 
 
@@ -553,7 +586,7 @@ dbus_bus_request_name(con, service_name)
     CODE:
         dbus_error_init(&error);
         if (!(reply = dbus_bus_request_name(con, service_name, 0, &error))) {
-          croak(error.message);
+          _croak_error(&error);
         }
         RETVAL = reply;
 
@@ -584,9 +617,7 @@ _open(address)
         server = dbus_server_listen(address, &error);
         PD_DEBUG("Created server %x on address %s", server, address);
         if (!server) {
-          // XXX fixme
-          //dbus_error_free(&error);
-          croak(error.message);
+          _croak_error(&error);
         }
         if (!dbus_server_set_auth_mechanisms(server, NULL)) {
             croak("not enough memory to server auth mechanisms");
@@ -671,9 +702,7 @@ _open(type)
         dbus_error_init(&error);
         con = dbus_bus_get(type, &error);
         if (!con) {
-          // XXX fixme
-          //dbus_error_free(error);
-          croak(error.message);
+          _croak_error(&error);
         }
         RETVAL = con;
     OUTPUT:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libnet-dbus-perl.git



More information about the Pkg-perl-cvs-commits mailing list