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

Commit

Permalink
unix: fix pointer ownership bug
Browse files Browse the repository at this point in the history
libuv realloc'd a pointer that belonged to and was later freed by libev.
  • Loading branch information
bnoordhuis committed Sep 26, 2011
1 parent f6a365e commit 9673abe
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/unix/fs.c
Expand Up @@ -149,19 +149,20 @@ static int uv__fs_after(eio_req* eio) {
case UV_FS_READLINK:
if (req->result == -1) {
req->ptr = NULL;
} else {
assert(req->result > 0);

if ((name = realloc(req->eio->ptr2, req->result + 1)) == NULL) {
/* Not enough memory. Reuse buffer, chop off last byte. */
name = req->eio->ptr2;
req->result--;
}
break;
}
assert(req->result > 0);

/* Make zero-terminated copy of req->eio->ptr2 */
if ((req->ptr = name = malloc(req->result + 1))) {
memcpy(name, req->eio->ptr2, req->result);
name[req->result] = '\0';
req->ptr = name;
req->result = 0;
}
else {
req->errorno = ENOMEM;
req->result = -1;
}
break;

default:
Expand Down

0 comments on commit 9673abe

Please sign in to comment.