diff src/recpt1.c @ 144:bf96eac4dbb1

Changed to a variable length buffer of splitbuf_t
author Naoya OYAMA <naoya.oyama@gmail.com>
date Wed, 01 Aug 2012 23:23:24 +0900
parents d65c15276b5e
children 066f33b2213a
line wrap: on
line diff
--- a/src/recpt1.c	Sun Jul 29 23:16:30 2012 +0900
+++ b/src/recpt1.c	Wed Aug 01 23:23:24 2012 +0900
@@ -418,6 +418,8 @@
     buf.size = 0;
     buf.data = NULL;
     splitbuf.size = 0;
+    splitbuf.buffer_length = 0;
+    splitbuf.buffer = NULL;
 
     if(wfd == -1)
         fileless = TRUE;
@@ -454,6 +456,15 @@
 
         if(use_splitter) {
             splitbuf.size = 0;
+            if(splitbuf.buffer_length < buf.size && buf.size > 0) {
+                splitbuf.buffer = realloc(splitbuf.buffer, buf.size);
+                if(NULL == splitbuf.buffer) {
+                    fprintf(stderr, "splitbuf.buffer realloc failed\n");
+                    use_splitter = FALSE;
+                    goto fin;
+                }
+                splitbuf.buffer_length = buf.size;
+            }
 
             while(buf.size) {
                 /* $BJ,N%BP>](BPID$B$NCj=P(B */
@@ -608,6 +619,11 @@
                         pthread_kill(signal_thread, SIGPIPE);
                 }
             }
+            if(use_splitter) {
+                free(splitbuf.buffer);
+                splitbuf.buffer = NULL;
+                splitbuf.buffer_length = 0;
+            }
 
             break;
         }