Skip to content

Commit abaab85

Browse files
committedNov 9, 2018
fix an allocation bug
1 parent 8a7d6b9 commit abaab85

File tree

3 files changed

+195
-24
lines changed

3 files changed

+195
-24
lines changed
 

‎package-lock.json

+191-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-stringbuilder",
3-
"version": "2.2.3",
3+
"version": "2.2.4",
44
"description": "An easy and fast in-memory string builder for Node.js.",
55
"main": "index.js",
66
"scripts": {
@@ -37,4 +37,4 @@
3737
"dependencies": {
3838
"bindings": "^1.3.0"
3939
}
40-
}
40+
}

‎src/node-stringbuilder.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1312,11 +1312,12 @@ napi_value ToBuffer(napi_env env, napi_callback_info info){
13121312
size_t sourceDataSize;
13131313
napi_get_value_string_utf8(env, tempString, NULL, 0, &sourceDataSize);
13141314
++sourceDataSize;
1315-
char utf8Data[sourceDataSize];
1315+
char* utf8Data = (char*)malloc(sizeof(char) * sourceDataSize);
13161316
napi_get_value_string_utf8(env, tempString, utf8Data, sourceDataSize, &sourceDataSize);
13171317
napi_value result;
13181318
char* data;
13191319
napi_create_buffer_copy(env, sourceDataSize, utf8Data, (void**)(&data), &result);
1320+
free(utf8Data);
13201321
return result;
13211322
}
13221323

0 commit comments

Comments
 (0)
Please sign in to comment.