FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

StrArray memory fix by mattyclarkson · Pull Request #454 · nodegit/nodegit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cc  (1) .h  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class StrArrayConverter {
private:
static git_strarray *ConvertArray(Array *val);
static git_strarray *ConvertString(Handle<String> val);
static git_strarray *AllocStrArray(const size_t count);
static git_strarray *ConstructStrArray(int argc, char** argv);
};

Expand Down
17 changes: 11 additions & 6 deletions generate/templates/manual/src/str_array_converter.cc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
}
}

static git_strarray * StrArrayConverter::AllocStrArray(const size_t count) {
const size_t size = sizeof(git_strarray) + (sizeof(char*) * count);
uint8_t* memory = reinterpret_cast<uint8_t*>(malloc(size));
git_strarray *result = reinterpret_cast<git_strarray *>(memory);
result->count = count;
result->strings = reinterpret_cast<char**>(memory + sizeof(git_strarray));
return result;
}

git_strarray *StrArrayConverter::ConvertArray(Array *val) {
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
result->count = val->Length();
result->strings = (char **)malloc(sizeof(char*) * result->count);
git_strarray *result = AllocStrArray(val->Length());

for(size_t i = 0; i < result->count; i++) {
NanUtf8String entry(val->Get(i));
Expand All @@ -47,9 +54,7 @@ git_strarray* StrArrayConverter::ConvertString(Handle<String> val) {
}

git_strarray *StrArrayConverter::ConstructStrArray(int argc, char** argv) {
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
result->count = argc;
result->strings = (char **)malloc(sizeof(char*) * result->count);
git_strarray *result = AllocStrArray(argc);

for(size_t i = 0; i < result->count; i++) {
result->strings[i] = strdup(argv[i]);
Expand Down

Back | FazBrowse Home | New Git URL