diff options
author | Tom Rini <trini@konsulko.com> | 2017-10-09 20:19:39 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-10-09 20:19:39 -0400 |
commit | ebdd65258bad89b2da6cce4265c858ee0d5a9440 (patch) | |
tree | f2002a9b676849b0697ab9cb494b7ed4f45e8130 /arch | |
parent | 74d90d17eebfeeefd91776e3deb7901c122bef7f (diff) | |
parent | 04d0da51578e12bd7c490aa70ed581ee5f9dcfea (diff) | |
download | u-boot-ebdd65258bad89b2da6cce4265c858ee0d5a9440.tar.gz |
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'arch')
-rw-r--r-- | arch/sandbox/cpu/os.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 22d6aab534..c524957b6c 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -319,6 +319,7 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) DIR *dir; int ret; char *fname; + char *old_fname; int len; int dirlen; @@ -344,16 +345,23 @@ int os_dirent_ls(const char *dirname, struct os_dirent_node **headp) break; } next = malloc(sizeof(*node) + strlen(entry->d_name) + 1); - if (dirlen + strlen(entry->d_name) > len) { - len = dirlen + strlen(entry->d_name); - fname = realloc(fname, len); - } - if (!next || !fname) { - free(next); + if (!next) { os_dirent_free(head); ret = -ENOMEM; goto done; } + if (dirlen + strlen(entry->d_name) > len) { + len = dirlen + strlen(entry->d_name); + old_fname = fname; + fname = realloc(fname, len); + if (!fname) { + free(old_fname); + free(next); + os_dirent_free(head); + ret = -ENOMEM; + goto done; + } + } next->next = NULL; strcpy(next->name, entry->d_name); switch (entry->d_type) { |