be a bit more friendly on systems that behave badly (consume lots of
authorAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 1997 17:29:51 +0000 (17:29 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 15 Dec 1997 17:29:51 +0000 (17:29 +0000)
ram) when you realloc() up by a small amount at a time

flist.c

diff --git a/flist.c b/flist.c
index 2ec8318..1ae8c34 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -316,12 +316,15 @@ static void send_file_name(int f,struct file_list *flist,char *fname)
   if (!file) return;  
   
   if (flist->count >= flist->malloced) {
-    flist->malloced += 100;
-    flist->files = (struct file_struct *)realloc(flist->files,
-                                                sizeof(flist->files[0])*
-                                                flist->malloced);
-    if (!flist->files)
-      out_of_memory("send_file_name");
+         if (flist->malloced < 100)
+                 flist->malloced += 100;
+         else
+                 flist->malloced *= 1.8;
+         flist->files = (struct file_struct *)realloc(flist->files,
+                                                      sizeof(flist->files[0])*
+                                                      flist->malloced);
+         if (!flist->files)
+                 out_of_memory("send_file_name");
   }
 
   if (strcmp(file->name,"/")) {
@@ -504,12 +507,15 @@ struct file_list *recv_file_list(int f)
     int i = flist->count;
 
     if (i >= flist->malloced) {
-      flist->malloced += 100;
-      flist->files =(struct file_struct *)realloc(flist->files,
-                                                 sizeof(flist->files[0])*
-                                                 flist->malloced);
-      if (!flist->files)
-       goto oom;
+         if (flist->malloced < 100)
+                 flist->malloced += 100;
+         else
+                 flist->malloced *= 1.8;
+         flist->files =(struct file_struct *)realloc(flist->files,
+                                                     sizeof(flist->files[0])*
+                                                     flist->malloced);
+         if (!flist->files)
+                 goto oom;
     }
 
     receive_file_entry(&flist->files[i],flags,f);