Skip to content

Commit

Permalink
fs: mkdtemp shouldn't crash if no callback passed
Browse files Browse the repository at this point in the history
As it is, `fs.mkdtemp` crashes with a C++ assertion if the callback
function is not passed. This patch uses `maybeCallback` to create one,
if no callback function is passed.

PR-URL: nodejs#6828
Reviewed-By: Brian White <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
thefourtheye authored and jasnell committed May 20, 2016
1 parent 2ef8359 commit dcbf246
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,8 @@ SyncWriteStream.prototype.destroy = function() {

SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy;

fs.mkdtemp = function(prefix, options, callback) {
fs.mkdtemp = function(prefix, options, callback_) {
var callback = maybeCallback(callback_);
if (!prefix || typeof prefix !== 'string')
throw new TypeError('filename prefix is required');

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-fs-mkdtemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ fs.mkdtemp(
assert(common.fileExists(folder));
})
);

assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));

0 comments on commit dcbf246

Please sign in to comment.