gnome-mud r728 - in trunk: . src



Author: lharris
Date: Mon Feb 16 20:33:00 2009
New Revision: 728
URL: http://svn.gnome.org/viewvc/gnome-mud?rev=728&view=rev

Log:
Closed memory leaks, fixed cornercase where MCCP data would be decompressed twice.


Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/mud-connection-view.c
   trunk/src/mud-connections.c
   trunk/src/mud-telnet-handlers.c
   trunk/src/mud-telnet-msp.c
   trunk/src/mud-telnet.c
   trunk/src/mud-telnet.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Feb 16 20:33:00 2009
@@ -1,5 +1,3 @@
-GMUD_DEBUG = -Wall -O0 -g
-
 localedir = $(datadir)/locale
 INCLUDES =								\
 	-DLOCALEDIR=\"$(localedir)\"					\
@@ -10,7 +8,7 @@
 	-DDATADIR=\""$(datadir)"\"					\
 	-DLIBDIR=\""$(libdir)"\"					\
 	-DGLADEDIR=\""$(pkgdatadir)"\"					\
-	$(GMUD_CFLAGS) $(GMUD_DEBUG) $(MSP_CFLAGS)
+	$(GMUD_CFLAGS) $(MSP_CFLAGS)
 LDADD   = $(GMUD_LIBS) $(Z_LIBS) $(MSP_LIBS)
 AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\"
 

Modified: trunk/src/mud-connection-view.c
==============================================================================
--- trunk/src/mud-connection-view.c	(original)
+++ trunk/src/mud-connection-view.c	Mon Feb 16 20:33:00 2009
@@ -1024,8 +1024,9 @@
             mud_tray_update_icon(view->priv->tray, online);
         }
 
-        mud_telnet_process(view->priv->telnet, (guchar *)event->buffer,
-                           event->length, &length, &(view->priv->processed));
+        view->priv->processed =
+            mud_telnet_process(view->priv->telnet, (guchar *)event->buffer,
+                           event->length, &length);
 
         if(view->priv->processed != NULL)
         {
@@ -1067,6 +1068,12 @@
                     view->priv->connect_hook = FALSE;
                 }
 
+                if(view->priv->processed != NULL)
+                {
+                    g_message("freeing processed in m-c-v");
+                    g_string_free(view->priv->processed, TRUE);
+                }
+
                 buf = NULL;
             }
         }

Modified: trunk/src/mud-connections.c
==============================================================================
--- trunk/src/mud-connections.c	(original)
+++ trunk/src/mud-connections.c	Mon Feb 16 20:33:00 2009
@@ -553,9 +553,27 @@
 	    g_free(display_name);
 	}
 
+        for(char_entry = characters; char_entry != NULL;
+                char_entry = g_slist_next(char_entry))
+            if(char_entry->data)
+                g_free(char_entry->data);
+
+        if(characters)
+            g_slist_free(characters);
+
 	g_free(mud_name);
 	g_free(name_strip);
     }
+
+    for(mud_entry = muds; mud_entry != NULL;
+            mud_entry = g_slist_next(mud_entry))
+        if(mud_entry->data)
+            g_free(mud_entry->data);
+
+    if(muds)
+        g_slist_free(muds);
+
+
 }
 
 static void

Modified: trunk/src/mud-telnet-handlers.c
==============================================================================
--- trunk/src/mud-telnet-handlers.c	(original)
+++ trunk/src/mud-telnet-handlers.c	Mon Feb 16 20:33:00 2009
@@ -49,6 +49,7 @@
 void
 MudHandler_TType_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("TTYPE enabled.");
     handler->enabled = TRUE;
     telnet->ttype_iteration = 0;
 }
@@ -115,6 +116,7 @@
 {
     gint w, h;
 
+    g_message("NAWS enabled.");
     mud_telnet_get_parent_size(telnet, &w, &h);
     mud_telnet_set_parent_naws(telnet, TRUE);
 
@@ -141,6 +143,7 @@
 void
 MudHandler_ECHO_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("ECHO enabled.");
     mud_telnet_set_local_echo(telnet, FALSE);
 }
 
@@ -161,6 +164,7 @@
 void
 MudHandler_EOR_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("EOR enabled.");
     telnet->eor_enabled = TRUE;
 }
 
@@ -181,6 +185,7 @@
 void
 MudHandler_CHARSET_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("CHARSET enabled.");
     handler->enabled = TRUE;
 }
 
@@ -250,6 +255,7 @@
 void
 MudHandler_ZMP_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("ZMP enabled.");
     handler->enabled = TRUE;
     mud_zmp_init(telnet);
 }
@@ -314,6 +320,7 @@
 void
 MudHandler_MSP_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("MSP enabled.");
     handler->enabled = TRUE;
     mud_telnet_msp_init(telnet);
     telnet->msp_parser.enabled = TRUE;
@@ -337,6 +344,7 @@
 void
 MudHandler_MCCP_Enable(MudTelnet *telnet, MudTelnetHandler *handler)
 {
+    g_message("MCCP enabled.");
     handler->enabled = TRUE;
     telnet->mccp = FALSE;
 }
@@ -362,6 +370,7 @@
 MudHandler_MCCP_HandleSubNeg(MudTelnet *telnet, guchar *buf, 
         guint len, MudTelnetHandler *handler)
 {
+    g_message("MCCP Subneq.");
     telnet->mccp = TRUE;
     telnet->mccp_new = TRUE;
 

Modified: trunk/src/mud-telnet-msp.c
==============================================================================
--- trunk/src/mud-telnet-msp.c	(original)
+++ trunk/src/mud-telnet-msp.c	Mon Feb 16 20:33:00 2009
@@ -188,6 +188,10 @@
 	*len = telnet->msp_parser.output->len;
     }
 
+    g_message("Free'ing view->priv->processed.");
+    g_string_free(buf, TRUE);
+    *(&buf) = NULL;
+
     return ret;
 }
 

Modified: trunk/src/mud-telnet.c
==============================================================================
--- trunk/src/mud-telnet.c	(original)
+++ trunk/src/mud-telnet.c	Mon Feb 16 20:33:00 2009
@@ -338,8 +338,8 @@
     mud_telnet_send_sub_req(telnet, 5, (guchar)TELOPT_NAWS, w1, w0, h1, h0);
 }
 
-void
-mud_telnet_process(MudTelnet *telnet, guchar * buf, guint32 c, gint *len, GString **out_buf)
+GString *
+mud_telnet_process(MudTelnet *telnet, guchar * buf, guint32 c, gint *len)
 {
     guint32 i;
     guint32 count;
@@ -351,19 +351,23 @@
     if(telnet->mccp)
     {
         GString *ret = NULL;
-        gchar *str;
 
         // decompress the buffer.
         ret = mud_mccp_decompress(telnet, buf, c);
 
+        telnet->mccp_new = FALSE;
+
         if(ret == NULL)
-            return;
+        {
+            if(telnet->buffer)
+                g_string_free(telnet->buffer, TRUE);
+
+            return ret;
+        }
         else
         {
-            str = g_strdup(ret->str);
-            g_string_append(telnet->buffer, str);
+            g_string_append(telnet->buffer, ret->str);
             g_string_free(ret, TRUE);
-            g_free(str);
         }
     }
     else
@@ -391,8 +395,8 @@
 
                 if(ret == NULL)
                 {
-                    if(*out_buf != NULL) g_string_free(*out_buf, TRUE);
-                    *out_buf = g_string_new_len(telnet->processed->str, telnet->pos);
+                    GString *ret_string =
+                        g_string_new_len(telnet->processed->str, telnet->pos);
                     *len = telnet->pos;
 
                     telnet->pos= 0;
@@ -409,7 +413,7 @@
                         telnet->buffer = NULL;
                     }
 
-                    return;
+                    return ret_string;
                 }
 
                 if(telnet->buffer)
@@ -422,8 +426,8 @@
 
                 if(telnet->buffer->len == 0)
                 {
-                    if(*out_buf != NULL) g_string_free(*out_buf, TRUE);
-                    *out_buf = g_string_new_len(telnet->processed->str, telnet->pos);
+                    GString *ret_string =
+                        g_string_new_len(telnet->processed->str, telnet->pos);
                     *len = telnet->pos;
 
                     telnet->pos= 0;
@@ -439,7 +443,7 @@
                         g_string_free(telnet->buffer, TRUE);
                         telnet->buffer = NULL;
                     }
-                    return;
+                    return ret_string;
                 }
 
                 i = 0;
@@ -573,28 +577,30 @@
 	}
     }
 
+    if(telnet->buffer)
+    {
+        g_string_free(telnet->buffer, TRUE);
+        telnet->buffer = NULL;
+    }
+
     if(telnet->tel_state == TEL_STATE_TEXT)
     {
-	if(*out_buf != NULL) g_string_free(*out_buf, TRUE);
-	*out_buf = g_string_new_len(g_strdup(telnet->processed->str), telnet->pos);
-	*len = telnet->pos;
+        GString *ret =
+            g_string_new_len(g_strdup(telnet->processed->str), telnet->pos);
+        *len = telnet->pos;
 
         telnet->pos= 0;
 
         if(telnet->processed)
         {
-	    g_string_free(telnet->processed, TRUE);
-	    telnet->processed = g_string_new(NULL);
-	}
-    }
-    else
-	*out_buf = NULL;
+            g_string_free(telnet->processed, TRUE);
+            telnet->processed = g_string_new(NULL);
+        }
 
-    if(telnet->buffer)
-    {
-        g_string_free(telnet->buffer, TRUE);
-        telnet->buffer = NULL;
+        return ret;
     }
+
+    return NULL;
 }
 
 gchar*

Modified: trunk/src/mud-telnet.h
==============================================================================
--- trunk/src/mud-telnet.h	(original)
+++ trunk/src/mud-telnet.h	Mon Feb 16 20:33:00 2009
@@ -199,7 +199,7 @@
 
 void mud_telnet_register_handlers(MudTelnet *telnet);
 gint mud_telnet_isenabled(MudTelnet *telnet, guint8 option_number, gint him);
-void mud_telnet_process(MudTelnet *telnet, guchar * buf, guint32 count, gint *length, GString **out_buf);
+GString *mud_telnet_process(MudTelnet *telnet, guchar * buf, guint32 count, gint *length);
 void mud_telnet_send_sub_req(MudTelnet *telnet, guint32 count, ...);
 void mud_telnet_get_parent_size(MudTelnet *telnet, gint *w, gint *h);
 void mud_telnet_send_raw(MudTelnet *telnet, guint32 count, ...);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]