[SeaBIOS] [PATCH v5 4/7] set psize to 0 when romfile_loadfile failed
Hu Tao
hutao at cn.fujitsu.com
Wed Jun 26 11:15:02 CEST 2013
Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
src/romfile.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/romfile.c b/src/romfile.c
index ea71d1f..b1b89bb 100644
--- a/src/romfile.c
+++ b/src/romfile.c
@@ -51,28 +51,33 @@ romfile_loadfile(const char *name, int *psize)
{
struct romfile_s *file = romfile_find(name);
if (!file)
- return NULL;
+ goto failed;
int filesize = file->size;
if (!filesize)
- return NULL;
+ goto failed;
char *data = malloc_tmphigh(filesize+1);
if (!data) {
warn_noalloc();
- return NULL;
+ goto failed;
}
dprintf(5, "Copying romfile '%s' (len %d)\n", name, filesize);
int ret = file->copy(file, data, filesize);
if (ret < 0) {
free(data);
- return NULL;
+ goto failed;
}
if (psize)
*psize = filesize;
data[filesize] = '\0';
return data;
+
+failed:
+ if (psize)
+ *psize = 0;
+ return NULL;
}
// Attempt to load an integer from the given file - return 'defval'
--
1.8.3.1
More information about the SeaBIOS
mailing list