bug-cpio
[Top][All Lists]
Advanced

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

[Bug-cpio] [PATCH 1/2] writeout_final_defers() changes


From: Zdeněk Pavlas
Subject: [Bug-cpio] [PATCH 1/2] writeout_final_defers() changes
Date: Tue, 15 Nov 2011 13:58:53 +0100

- fix memory leak
- group output by inode
---
 src/copyout.c |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/src/copyout.c b/src/copyout.c
index ab6a243..d8c19a0 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -244,24 +244,29 @@ writeout_defered_file (struct cpio_file_stat *header, int 
out_file_des)
 static void
 writeout_final_defers (int out_des)
 {
-  struct deferment *d;
-  int other_count;
   while (deferouts != NULL)
     {
-      d = deferouts;
-      other_count = count_defered_links_to_dev_ino (&d->header);
-      if (other_count == 1)
-       {
-         writeout_defered_file (&d->header, out_des);
-       }
-      else
-       {
-         struct cpio_file_stat file_hdr;
-         file_hdr = d->header;
-         file_hdr.c_filesize = 0;
-         write_out_header (&file_hdr, out_des);
-       }
-      deferouts = deferouts->next;
+      struct deferment *h, *d;
+      struct deferment **tail = &deferouts;
+      for (h = d = deferouts; (d = d->next) != NULL;)
+        {
+          if (d->header.c_ino     == h->header.c_ino
+          && d->header.c_dev_maj == h->header.c_dev_maj
+          && d->header.c_dev_min == h->header.c_dev_min)
+            {
+              write_out_header (&h->header, out_des);
+              free_deferment (h);
+              h = d;
+            }
+          else
+            {
+              *tail = d;
+              tail = &d->next;
+            }
+        }
+      writeout_defered_file (&h->header, out_des);
+      free_deferment (h);
+      *tail = NULL;
     }
 }
 
-- 
1.7.4.4




reply via email to

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