diff --git a/src/unix/os390-syscalls.c b/src/unix/os390-syscalls.c index 260d7816..4a926c76 100644 --- a/src/unix/os390-syscalls.c +++ b/src/unix/os390-syscalls.c @@ -43,6 +43,7 @@ int scandir(const char* maindir, struct dirent*** namelist, int (*compar)(const struct dirent**, const struct dirent **)) { struct dirent** nl; + struct dirent** nl_copy; struct dirent* dirent; unsigned count; size_t allocated; @@ -66,11 +67,13 @@ int scandir(const char* maindir, struct dirent*** namelist, goto error; memcpy(copy, dirent, sizeof(*copy)); - nl = uv__realloc(nl, sizeof(*copy) * (count + 1)); - if (nl == NULL) { + nl_copy = uv__realloc(nl, sizeof(*copy) * (count + 1)); + if (nl_copy == NULL) { uv__free(copy); goto error; } + + nl = nl_copy; nl[count++] = copy; } }