comparison 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
comparison
equal deleted inserted replaced
65:e4088afd5281 66:4f79cf993737
75 fclose(f); 75 fclose(f);
76 return READ_FILE_NO_MEMORY; 76 return READ_FILE_NO_MEMORY;
77 } 77 }
78 78
79 if (fread(*data, 1, *size, f) != *size) { 79 if (fread(*data, 1, *size, f) != *size) {
80 fclose(f);
81 free(*data); 80 free(*data);
81 fclose(f);
82 return READ_FILE_READ_FAILED; 82 return READ_FILE_READ_FAILED;
83 } 83 }
84 84
85 fclose(f); 85 fclose(f);
86 86
180 if (ret != 0) { 180 if (ret != 0) {
181 if (ret == READ_FILE_TOO_LARGE) { 181 if (ret == READ_FILE_TOO_LARGE) {
182 return TooLarge; 182 return TooLarge;
183 } 183 }
184 if (ret == READ_FILE_UNREADABLE) { 184 if (ret == READ_FILE_UNREADABLE) {
185 /* TODO: work with errno ? */
185 return SeekFailed; 186 return SeekFailed;
186 } 187 }
187 if (ret == READ_FILE_READ_FAILED) { 188 if (ret == READ_FILE_READ_FAILED) {
189 /* TODO: work with ferror() or feof() ? */
188 return ReadFailed; 190 return ReadFailed;
189 } 191 }
190 return UnknownError; 192 return UnknownError;
191 } 193 }
192 194

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