Browse code

fix double close of file descriptor

git-svn: trunk@2214

Tomasz Kojm authored on 2006/08/27 06:42:40
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Sat Aug 26 23:41:08 CEST 2006 (tk)
2
+----------------------------------
3
+  * libclamav/mspack: fix double close of file descriptor, patch from NJH
4
+
1 5
 Fri Aug 25 21:23:59 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * freshclam/manager.c: "Cache-Control: no-cache" is now disabled by default.
... ...
@@ -685,12 +685,16 @@ static struct mscabd_cabinet *cabd_dsearch(struct mscab_decompressor *base,
685 685
   off_t filelen;
686 686
   char *filename = "descriptor";
687 687
 
688
-  if (!base) return NULL;
688
+  if (!base) {
689
+      close(desc);
690
+      return NULL;
691
+  }
689 692
   sys = this->system;
690 693
 
691 694
   /* allocate a search buffer */
692 695
   search_buf = sys->alloc(sys, (size_t) this->param[MSCABD_PARAM_SEARCHBUF]);
693 696
   if (!search_buf) {
697
+    close(desc);
694 698
     this->error = MSPACK_ERR_NOMEMORY;
695 699
     return NULL;
696 700
   }
... ...
@@ -724,6 +728,7 @@ static struct mscabd_cabinet *cabd_dsearch(struct mscab_decompressor *base,
724 724
 
725 725
   /* free the search buffer */
726 726
   sys->free(search_buf);
727
+  close(desc);
727 728
 
728 729
   return (struct mscabd_cabinet *) cab;
729 730
 }
... ...
@@ -140,8 +140,8 @@ static struct mspack_file *msp_dopen(struct mspack_system *this,
140 140
 
141 141
   if ((fh = cli_malloc(sizeof(struct mspack_file_p)))) {
142 142
     fh->name = "descriptor";
143
-    fh->desc = desc;
144
-    if ((fh->fh = fdopen(desc, fmode))) return (struct mspack_file *) fh;
143
+    fh->desc = dup(desc);
144
+    if ((fh->fh = fdopen(fh->desc, fmode))) return (struct mspack_file *) fh;
145 145
     free(fh);
146 146
   }
147 147
   return NULL;