mirror of https://github.com/nodejs/node.git
src: fix memory leak in fs.writeSync error path
The SYNC_CALL macro returns on error, bypassing the delete[] call.
Mea culpa, it looks like I introduced this memory leak back in 2013,
in commit d2b80b8a
("src: clean up FSReqWrap").
PR-URL: https://github.com/iojs/io.js/pull/1092
Reviewed-By: Fedor Indutny <fedor@indutny.com>
pull/1092/head
parent
648fc63cd1
commit
528d8786ff
|
@ -853,9 +853,14 @@ static void WriteString(const FunctionCallbackInfo<Value>& args) {
|
|||
uv_buf_t uvbuf = uv_buf_init(const_cast<char*>(buf), len);
|
||||
|
||||
if (!req->IsObject()) {
|
||||
// SYNC_CALL returns on error. Make sure to always free the memory.
|
||||
struct Delete {
|
||||
inline explicit Delete(char* pointer) : pointer_(pointer) {}
|
||||
inline ~Delete() { delete[] pointer_; }
|
||||
char* const pointer_;
|
||||
};
|
||||
Delete delete_on_return(ownership == FSReqWrap::MOVE ? buf : nullptr);
|
||||
SYNC_CALL(write, nullptr, fd, &uvbuf, 1, pos)
|
||||
if (ownership == FSReqWrap::MOVE)
|
||||
delete[] buf;
|
||||
return args.GetReturnValue().Set(SYNC_RESULT);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue