changeset 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 e4088afd5281
children 1bf41957418f
files common/listutil.c
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
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/