Re: core segfaults (Yahoo?)

"A. Craig West" <[email protected]> Thu, 11 Mar 2004 19:44:48 -0500 (EST)
Newsgroups gmane.network.everybuddy.devel
Message-ID <[email protected]>
Here are the diffs for all of my fixes for various issues. I need Philip's
advice for the libyahoo2.c changes, seeing as I just un-commented some
commented out code, and I'm certain there was some reason for it to be
commented out in the first place.

-------------------------Patch Begins -----------------------------
Index: core/src/plugin.c
===================================================================
--- core/src/plugin.c	(revision 306)
+++ core/src/plugin.c	(working copy)
@@ -121,6 +121,18 @@
 }
 
 #if HAVE_LIBLTDL  // MOTHBALLED
+static eb_plugin * create_plugin(char * fnam)
+{
+  eb_plugin * plugin = (eb_plugin *)malloc(sizeof(eb_plugin));
+  plugin->filename=(char *)strdup(fnam);
+  plugin->info=NULL;
+  plugin->status=PLUGIN_NOT_LOADED;
+  plugin->errormsg=NULL;
+  plugins=e_list_append(plugins, plugin);
+
+  return plugin;
+}
+
 static void add_error_entry(char * fnam, char * errormsg)
 {
   eb_plugin * plugin;
@@ -128,18 +140,21 @@
 
   if((plugin=plugin_by_name(fnam))==NULL)
   {
-    plugin=(eb_plugin *)malloc(sizeof(eb_plugin));
+    plugin=create_plugin(fnam);
     isnew=1;
   }
 
-  plugin->filename=fnam;
+  if (plugin->info)
+    free(plugin->info);
+  if (plugin->errormsg)
+    free(plugin->errormsg);
+
   plugin->info=NULL;
   plugin->status=PLUGIN_CANNOT_LOAD;
   plugin->errormsg=(char *)strdup(errormsg);
 
   if(isnew)
   {
-    plugins=e_list_append(plugins, plugin);
     new_plugin_notify(plugin);
   } else {
     plugin_update_notify(plugin);
@@ -154,6 +169,7 @@
   dlhandle dat;
   eb_plugin_info * info;
   eb_plugin * plugin;
+  int isnew=0;
 
   full_path=(char *)malloc(strlen(path)+strlen(fnam)+2);
   sprintf(full_path, "%s/%s", path, fnam);
@@ -192,12 +208,27 @@
   // Now, we dispatch based on plugin type. Are we all sitting comfortably?
 
   if(plugin==NULL)
-  { plugin=(eb_plugin *)malloc(sizeof(eb_plugin)); }
+  {
+    plugin=create_plugin(full_path);
+    isnew=1;
+  }
 
+  if (plugin->info)
+    free(plugin->info);
+  if (plugin->errormsg)
+    free(plugin->errormsg);
+
   plugin->status=PLUGIN_LOADED;
   plugin->errormsg=NULL;
   plugin->info=info;
 
+  if(isnew)
+  {
+    new_plugin_notify(plugin);
+  } else {
+    plugin_update_notify(plugin);
+  }
+
   free(full_path);
 
   info->init();
Index: core/plugins/yahoo/yahoo.c
===================================================================
--- core/plugins/yahoo/yahoo.c	(revision 307)
+++ core/plugins/yahoo/yahoo.c	(working copy)
@@ -41,6 +41,7 @@
 #include "yahoo2.h"
 #include "yahoo2_callbacks.h"
 #include "yahoo_util.h"
+#include "yahoo_debug.h"
 
 typedef struct _eb_ylad
 {
@@ -376,6 +377,7 @@
 {
   EList * states = NULL;
   printf("Hi-ho, hi-ho, Yahoo here we go!\n");
+  /*yahoo_set_log_level(YAHOO_LOG_DEBUG);*/
 
   memset(&yahoo_callbacks, 0, sizeof(yahoo_callbacks));
   
@@ -739,7 +741,8 @@
  *      members - the initial members of the conference (null terminated list)
  */
 void ext_yahoo_got_conf_invite(int id, char *who, char *room, char *msg, YList *members)
-{}
+{
+}
 
 
 
@@ -754,7 +757,8 @@
  * 	msg  - the declining message
  */
 void ext_yahoo_conf_userdecline(int id, char *who, char *room, char *msg)
-{}
+{
+}
 
 
 
@@ -768,7 +772,8 @@
  * 	room - the room joined
  */
 void ext_yahoo_conf_userjoin(int id, char *who, char *room)
-{}
+{
+}
 
 
 
@@ -782,7 +787,8 @@
  * 	room - the room left
  */
 void ext_yahoo_conf_userleave(int id, char *who, char *room)
-{}
+{
+}
 
 
 /*
@@ -795,7 +801,8 @@
  *      members - the initial members of the chatroom (null terminated YList of yahoo_chat_member's) Must be freed by the client
  */
 void ext_yahoo_chat_cat_xml(int id, char *xml)
-{}
+{
+}
 
 /*
  * Name: ext_yahoo_chat_join
@@ -808,7 +815,8 @@
  * 	fd      - the socket where the connection is coming from (for tracking)
  */
 void ext_yahoo_chat_join(int id, char *room, char *topic, YList *members, int fd)
-{}
+{
+}
 
 /*
  * Name: ext_yahoo_chat_userjoin
@@ -819,7 +827,8 @@
  * 	who  - the user who has joined, Must be freed by the client
  */
 void ext_yahoo_chat_userjoin(int id, char *room, struct yahoo_chat_member *who)
-{}
+{
+}
 
 
 
@@ -833,7 +842,8 @@
  * 	who  - the user who has left (Just the User ID)
  */
 void ext_yahoo_chat_userleave(int id, char *room, char *who)
-{}
+{
+}
 
 
 
@@ -1331,13 +1341,14 @@
 {
   yahoo_connect_callback cb;
   void * data;
+  int done;
 } conn_cb_data;
 
 static void conn_cb(int fd, void * data)
 {
   conn_cb_data * d = (conn_cb_data *)data;
   d->cb(fd, (fd >= 0) ? (0) : (errno), d->data);
-  free(d);
+  d->done = 1;
 }
 
 /*
@@ -1361,9 +1372,14 @@
 int ext_yahoo_connect_async(int id, char *host, int port, 
 		yahoo_connect_callback callback, void *callback_data)
 {
+  int rval;
   conn_cb_data * d = (conn_cb_data *)malloc(sizeof(conn_cb_data));
   d->cb = callback;
   d->data = callback_data;
-  return eb_connect_socket(host, port, conn_cb, d);
+  d->done = 0;
+  rval = eb_connect_socket(host, port, conn_cb, d);
+  if (d->done && rval > 0)
+    return 0; // Successful, but callback has already been called
+  return rval;
 }
 
Index: core/plugins/yahoo/libyahoo2.c
===================================================================
--- core/plugins/yahoo/libyahoo2.c	(revision 306)
+++ core/plugins/yahoo/libyahoo2.c	(working copy)
@@ -373,7 +373,7 @@
 }
 
 /* call repeatedly to get the next one */
-/*
+
 static struct yahoo_input_data * find_input_by_id(int id)
 {
 	YList *l;
@@ -384,8 +384,8 @@
 	}
 	return NULL;
 }
-*/
 
+
 static struct yahoo_input_data * find_input_by_id_and_webcam_user(int id, const char * who)
 {
 	YList *l;
@@ -3612,9 +3612,9 @@
 	}
 
 	
-/*	do {
+	do {
 		yahoo_input_close(yid);
-	} while((yid = find_input_by_id(id)));*/
+	} while((yid = find_input_by_id(id)));
 	
 }
 
-------------------------Patch Ends -----------------------------
-- 
Craig West         Ph: (416) 666-1645	|  It's not a bug,
[email protected]              	|  It's a feature...