Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
windows: don't alloc readdir buffer for empty dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Oct 11, 2011
1 parent 4ac1309 commit 40b64a8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/win/fs.c
Expand Up @@ -342,7 +342,7 @@ void fs__rmdir(uv_fs_t* req, const char* path) {

void fs__readdir(uv_fs_t* req, const char* path, int flags) {
int result;
char* buf, *ptr, *name;
char* buf = NULL, *ptr, *name;
HANDLE dir;
WIN32_FIND_DATAA ent = {0};
size_t len = strlen(path);
Expand All @@ -365,12 +365,6 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
return;
}

buf = (char*)malloc(buf_size);
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

ptr = buf;
result = 0;

do {
Expand All @@ -379,6 +373,15 @@ void fs__readdir(uv_fs_t* req, const char* path, int flags) {
if (name[0] != '.' || (name[1] && (name[1] != '.' || name[2]))) {
len = strlen(name);

if (!buf) {
buf = (char*)malloc(buf_size);
if (!buf) {
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
}

ptr = buf;
}

while ((ptr - buf) + len + 1 > buf_size) {
buf_size *= 2;
path2 = buf;
Expand Down

0 comments on commit 40b64a8

Please sign in to comment.