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

[PATCH 10/15] lowmem trimtemplates: fix leaks on error pathes



add appropriate fclose and a closedir.

Signed-off-by: maximilian attems <max@stro.at>
---
 packages/lowmem/trimtemplates.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/packages/lowmem/trimtemplates.c b/packages/lowmem/trimtemplates.c
index 34b2438..ce59703 100644
--- a/packages/lowmem/trimtemplates.c
+++ b/packages/lowmem/trimtemplates.c
@@ -39,6 +39,7 @@ int trimtemplate(char *filename) {
 
      if ((tmpfd = fopen(tmpfilename, "w")) == NULL) {
 	  perror("unable to open temp file");
+	  fclose(fd);
 	  return 0;
      }
 
@@ -65,6 +66,8 @@ int trimtemplate(char *filename) {
 	  }
 	  if (ignore == 0 && fputs(template_line, tmpfd) == EOF) {
 	       perror("unable to write to temp file");
+	       fclose(tmpfd);
+	       fclose(fd);
 	       return 0;
 	  }
      }
@@ -116,6 +119,7 @@ int main(int argc, char** argv) {
 		    snprintf(abs_path_file_name,
 			     FILENAME_LENGTH,"%s/%s",dir,dit->d_name);
 		    if (trimtemplate(abs_path_file_name) == 0) {
+			 closedir(dip);
 			 return 0;
 		    }
 	       }
-- 
1.7.2.3


Reply to: