gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23104 - Extractor/src/main


From: gnunet
Subject: [GNUnet-SVN] r23104 - Extractor/src/main
Date: Sat, 4 Aug 2012 22:16:10 +0200

Author: grothoff
Date: 2012-08-04 22:16:10 +0200 (Sat, 04 Aug 2012)
New Revision: 23104

Modified:
   Extractor/src/main/extractor_ipc_gnu.c
   Extractor/src/main/extractor_plugpath.c
Log:
fix recursive strtok issue by using strtok_r

Modified: Extractor/src/main/extractor_ipc_gnu.c
===================================================================
--- Extractor/src/main/extractor_ipc_gnu.c      2012-08-04 19:57:47 UTC (rev 
23103)
+++ Extractor/src/main/extractor_ipc_gnu.c      2012-08-04 20:16:10 UTC (rev 
23104)
@@ -84,12 +84,15 @@
 
   /**
    * Buffer for reading data from the plugin.
-   * FIXME: we might want to grow this
-   * buffer dynamically instead of always using 32 MB!
    */
-  char data[MAX_META_DATA];
+  char *mdata;
 
   /**
+   * Size of the 'mdata' buffer.
+   */
+  size_t mdata_size;
+
+  /**
    * Memory segment shared with this process.
    */
   struct EXTRACTOR_SharedMemory *shm;
@@ -280,6 +283,13 @@
       LOG_STRERROR ("malloc");
       return NULL;
     }
+  channel->mdata_size = 1024;
+  if (NULL == (channel->mdata = malloc (channel->mdata_size)))
+    {
+      LOG_STRERROR ("malloc");
+      free (channel);
+      return NULL;      
+    }  
   channel->shm = shm;
   channel->plugin = plugin;
   channel->size = 0;
@@ -367,6 +377,7 @@
     LOG_STRERROR ("close");
   if (0 != close (channel->cpipe_in))
     LOG_STRERROR ("close");
+  free (channel->mdata);
   free (channel);
 }
 
@@ -432,6 +443,7 @@
   struct EXTRACTOR_Channel *channel;
   ssize_t ret;
   ssize_t iret;
+  char *ndata;
 
   FD_ZERO (&to_check);
   max = -1;
@@ -464,12 +476,33 @@
        continue;
       if (! FD_ISSET (channel->cpipe_out, &to_check))
        continue;
+      if (channel->mdata_size == channel->size)
+       {
+         /* not enough space, need to grow allocation (if allowed) */
+         if (MAX_META_DATA == channel->mdata_size)
+           {
+             LOG ("Inbound message from channel too large, aborting\n");
+             EXTRACTOR_IPC_channel_destroy_ (channel);
+             channels[i] = NULL;             
+           }
+         channel->mdata_size *= 2;
+         if (channel->mdata_size > MAX_META_DATA)
+           channel->mdata_size = MAX_META_DATA;
+         if (NULL == (ndata = realloc (channel->mdata,
+                                       channel->mdata_size)))
+           {
+             LOG_STRERROR ("realloc");
+             EXTRACTOR_IPC_channel_destroy_ (channel);
+             channels[i] = NULL;             
+           }
+         channel->mdata = ndata;
+       }
       if ( (-1 == (iret = read (channel->cpipe_out,
-                               &channel->data[channel->size],
-                               MAX_META_DATA - channel->size)) ) ||
+                               &channel->mdata[channel->size],
+                               channel->mdata_size - channel->size)) ) ||
           (0 == iret) ||
           (-1 == (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin,
-                                                      channel->data, 
+                                                      channel->mdata, 
                                                       channel->size + iret, 
                                                       proc, proc_cls)) ) )
        {
@@ -480,8 +513,8 @@
        }
       else
        {
-         memmove (channel->data,
-                  &channel->data[ret],
+         memmove (channel->mdata,
+                  &channel->mdata[ret],
                   channel->size + iret - ret);
          channel->size = channel->size + iret - ret;
        }

Modified: Extractor/src/main/extractor_plugpath.c
===================================================================
--- Extractor/src/main/extractor_plugpath.c     2012-08-04 19:57:47 UTC (rev 
23103)
+++ Extractor/src/main/extractor_plugpath.c     2012-08-04 20:16:10 UTC (rev 
23104)
@@ -424,6 +424,7 @@
   char *path;
   char *prefix;
   char *d;
+  char *saveptr;
 
   prefix = NULL;
   if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX")))
@@ -433,9 +434,9 @@
          LOG_STRERROR ("strdup");
          return;
        }
-      for (prefix = strtok (d, PATH_SEPARATOR_STR);
+      for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr);
           NULL != prefix;
-          prefix = strtok (NULL, PATH_SEPARATOR_STR))
+          prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr))
        pp (pp_cls, prefix);    
       free (d);
       return;




reply via email to

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