diff common/listutil.c @ 66:4f79cf993737

Tiny improvement: free resources first that you have aquired last. Added TODO for better error reporting.
author Bernhard Reiter <bernhard@intevation.de>
date Tue, 18 Mar 2014 16:37:40 +0100
parents b8cd573bd3ac
children 8ffbb48528ae
line wrap: on
line diff
--- a/common/listutil.c	Tue Mar 18 14:23:30 2014 +0000
+++ b/common/listutil.c	Tue Mar 18 16:37:40 2014 +0100
@@ -77,8 +77,8 @@
     }
 
     if (fread(*data, 1, *size, f) != *size) {
+        free(*data);
         fclose(f);
-        free(*data);
         return READ_FILE_READ_FAILED;
     }
 
@@ -182,9 +182,11 @@
             return TooLarge;
         }
         if (ret == READ_FILE_UNREADABLE) {
+            /* TODO: work with errno ? */
             return SeekFailed;
         }
         if (ret == READ_FILE_READ_FAILED) {
+            /* TODO: work with ferror() or feof() ? */
             return ReadFailed;
         }
         return UnknownError;

http://wald.intevation.org/projects/trustbridge/