[2775] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH] Moved location of canonicalize_file_name in owl_util_file_deleteline so that we don't need to fclose the file if we can't canonicalize the name.

daemon@ATHENA.MIT.EDU (Jason Gross)
Sat Nov 13 23:59:13 2010

From: Jason Gross <jgross@MIT.EDU>
To: barnowl-dev@mit.edu
Cc: Jason <jgross@mit.edu>
Date: Sat, 13 Nov 2010 23:59:10 -0500

From: Jason <jgross@mit.edu>

I think the added free(actual_filename) work slightly better than adding
fclose to if (actual_filename == NULL).  (The previous state, which had
neither, was an accident.)
---
 util.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/util.c b/util.c
index 44c4cc5..e8e5c88 100644
--- a/util.c
+++ b/util.c
@@ -389,22 +389,24 @@ int owl_util_file_deleteline(const char *filename, const char *line, int backup)
   struct stat st;
   int numremoved = 0;
 
+  /* canonicalize filename and handle errors */
+  actual_filename = canonicalize_file_name(filename);
+  if (actual_filename == NULL) {
+    owl_function_error("Cannot canonicalize file name %s: %s",
+		       actual_filename, strerror(errno));
+    return -1;
+  }
+
   if ((old = fopen(filename, "r")) == NULL) {
     owl_function_error("Cannot open %s (for reading): %s",
 		       filename, strerror(errno));
+    free(actual_filename);
     return -1;
   }
 
   if (fstat(fileno(old), &st) != 0) {
     owl_function_error("Cannot stat %s: %s", filename, strerror(errno));
-    return -1;
-  }
-
-  /* canonicalize filename and handle errors */
-  actual_filename = canonicalize_file_name(filename);
-  if (actual_filename == NULL) {
-    owl_function_error("Cannot canonicalize file name %s: %s",
-		       actual_filename, strerror(errno));
+    free(actual_filename);
     return -1;
   }
 
-- 
1.7.1


home help back first fref pref prev next nref lref last post