agent: Hold a reference to pseudotcp while calling its callbacks
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 3 Jan 2014 15:03:08 +0000 (15:03 +0000)
committerOlivier CrĂȘte <olivier.crete@collabora.com>
Fri, 31 Jan 2014 06:48:59 +0000 (01:48 -0500)
This prevents the pseudotcp socket from being destroyed from within a
callback.

agent/pseudotcp.c

index 1c9a1b9..dda3157 100644 (file)
@@ -874,11 +874,20 @@ gboolean
 pseudo_tcp_socket_notify_packet(PseudoTcpSocket *self,
     const gchar * buffer, guint32 len)
 {
+  gboolean retval;
+
   if (len > MAX_PACKET) {
     //LOG_F(WARNING) << "packet too large";
     return FALSE;
   }
-  return parse(self, (guint8 *) buffer, len);
+
+  /* Hold a reference to the PseudoTcpSocket during parsing, since it may be
+   * closed from within a callback. */
+  g_object_ref (self);
+  retval = parse (self, (guint8 *) buffer, len);
+  g_object_unref (self);
+
+  return retval;
 }
 
 gboolean