Skip to content

Commit

Permalink
Fix readlink related memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
cmb69 committed Jul 16, 2020
1 parent dd1d119 commit 27bb0d9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions win32/ioutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,14 @@ __forceinline static ssize_t php_win32_ioutil_readlink(const char *path, char *b

ret_buf = php_win32_ioutil_conv_w_to_any(retw, ret, &ret_buf_len);
if (!ret_buf || ret_buf_len >= buf_len || ret_buf_len >= MAXPATHLEN) {
free(ret_buf);

This comment has been minimized.

Copy link
@staabm

staabm Jul 16, 2020

Contributor

Does this make sense for the first part of the condition?

When !ret_buf call free(ret_buf); ?

This comment has been minimized.

Copy link
@nikic

nikic Jul 16, 2020

Member

free(NULL) is a no-op, so it's fine.

free(pathw);
SET_ERRNO_FROM_WIN32_CODE(ERROR_BAD_PATHNAME);
return -1;
}
memcpy(buf, ret_buf, ret_buf_len + 1);

free(ret_buf);
free(pathw);

return ret_buf_len;
Expand Down

0 comments on commit 27bb0d9

Please sign in to comment.