gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r12135 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r12135 - gnunet/src/util
Date: Fri, 2 Jul 2010 18:41:31 +0200

Author: nevans
Date: 2010-07-02 18:41:31 +0200 (Fri, 02 Jul 2010)
New Revision: 12135

Modified:
   gnunet/src/util/connection.c
   gnunet/src/util/server_mst.c
Log:
thought realloc was problem, but not properly freeing memory. believe that 
transport segfault *could* be related to growing connection buffers on 
demand... appreciate another look if someone has the time (Christian...)

Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c        2010-07-02 16:07:14 UTC (rev 12134)
+++ gnunet/src/util/connection.c        2010-07-02 16:41:31 UTC (rev 12135)
@@ -556,6 +556,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Freeing memory of connection %p.\n", sock);
 #endif
+  GNUNET_free (sock->write_buffer);
   GNUNET_free (sock);
 }
 
@@ -1586,16 +1587,25 @@
                                          notify, void *notify_cls)
 {
   size_t temp_size;
+#if !REALLOC
+  char *temp_buf;
+#endif
   if (sock->nth.notify_ready != NULL)
     return NULL;
   GNUNET_assert (notify != NULL);
   if ((sock->write_buffer_size < size) && (size < 
GNUNET_SERVER_MAX_MESSAGE_SIZE))
     {
-      temp_size = sock->write_buffer_size + size;
+      temp_size = sock->write_buffer_size + size + 1;
       if (temp_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
         temp_size = GNUNET_SERVER_MAX_MESSAGE_SIZE;
-
+#if REALLOC
       sock->write_buffer = GNUNET_realloc(sock->write_buffer, temp_size);
+#else
+      temp_buf = GNUNET_malloc(temp_size);
+      memcpy(temp_buf, sock->write_buffer, sock->write_buffer_size);
+      GNUNET_free(sock->write_buffer);
+      sock->write_buffer = temp_buf;
+#endif
       sock->write_buffer_size = temp_size;
     }
   GNUNET_assert (sock->write_buffer_size >= size);

Modified: gnunet/src/util/server_mst.c
===================================================================
--- gnunet/src/util/server_mst.c        2010-07-02 16:07:14 UTC (rev 12134)
+++ gnunet/src/util/server_mst.c        2010-07-02 16:41:31 UTC (rev 12135)
@@ -129,6 +129,10 @@
   size_t delta;
   uint16_t want;
   char *ibuf;
+
+#if !REALLOC
+  char *temp_buf;
+#endif
   int need_align;
   unsigned long offset;
   int ret;
@@ -142,11 +146,17 @@
 #endif
   if ((size > mst->curr_buf) && (size < GNUNET_SERVER_MAX_MESSAGE_SIZE)) /* 
Received bigger message than we can currently handle! */
     {
-      newsize = mst->curr_buf + size; /* How much space do we need? */
+      newsize = mst->curr_buf + size + 1; /* How much space do we need? */
       if (newsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
-        newsize = GNUNET_SERVER_MAX_MESSAGE_SIZE; /* Check it's not bigger 
than GNUNET_SERVER_MAX_MESSAGE_SIZE */
-
+        newsize = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; /* Check it's not bigger 
than GNUNET_SERVER_MAX_MESSAGE_SIZE */
+#if REALLOC
       mst->hdr = GNUNET_realloc(mst->hdr, newsize);
+#else
+      temp_buf = GNUNET_malloc(newsize);
+      memcpy(temp_buf, mst->hdr, mst->curr_buf);
+      GNUNET_free(mst->hdr);
+      mst->hdr = temp_buf;
+#endif
       mst->curr_buf = newsize;
     }
 
@@ -303,6 +313,7 @@
 void
 GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst)
 {
+  GNUNET_free (mst->hdr);
   GNUNET_free (mst);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]