Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9eb357e

Browse files
Fix leak strdup in oid
1 parent 5160975 commit 9eb357e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

generate/templates/partials/convert_from_v8.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
if (arrayVal->IsString()) {
5959
// Try and parse in a string to a git_oid
6060
Nan::Utf8String oidString(Nan::To<v8::String>(arrayVal).ToLocalChecked());
61-
62-
if (git_oid_fromstr(&from_{{ name }}[i], (const char *) strdup(*oidString)) != GIT_OK) {
61+
string str = string(*oidString);
62+
if (git_oid_fromstr(&from_{{ name }}[i], str.c_str()) != GIT_OK) {
6363
if (git_error_last()) {
6464
return Nan::ThrowError(git_error_last()->message);
6565
} else {
@@ -90,8 +90,8 @@
9090
// Try and parse in a string to a git_oid
9191
Nan::Utf8String oidString(Nan::To<v8::String>(info[{{ jsArg }}]).ToLocalChecked());
9292
git_oid *oidOut = (git_oid *)malloc(sizeof(git_oid));
93-
94-
if (git_oid_fromstr(oidOut, (const char *) strdup(*oidString)) != GIT_OK) {
93+
string str = string(*oidString);
94+
if (git_oid_fromstr(oidOut, str.c_str()) != GIT_OK) {
9595
free(oidOut);
9696

9797
if (git_error_last()) {

0 commit comments

Comments
 (0)