Skip to content

Commit bfc6b29

Browse files
committed
Use emalloc/estrdup/efree in v8js_commonjs.cc + fix memory leak
1 parent 2ce7e42 commit bfc6b29

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

v8js_commonjs.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extern "C" {
2424

2525
static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms)
2626
{
27-
char *term = (char *)malloc(PATH_MAX), *ptr = term;
27+
char *term = (char *) emalloc(PATH_MAX), *ptr = term;
2828

2929
// Initialise the term string
3030
*term = 0;
@@ -34,7 +34,7 @@ static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &ter
3434
if (strlen(term) > 0) {
3535
// Terminate term string and add to terms vector
3636
*ptr++ = 0;
37-
terms.push_back(strdup(term));
37+
terms.push_back(estrdup(term));
3838

3939
// Reset term string
4040
memset(term, 0, strlen(term));
@@ -50,12 +50,10 @@ static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &ter
5050
if (strlen(term) > 0) {
5151
// Terminate term string and add to terms vector
5252
*ptr++ = 0;
53-
terms.push_back(strdup(term));
53+
terms.push_back(estrdup(term));
5454
}
5555

56-
if (term > 0) {
57-
free(term);
58-
}
56+
efree(term);
5957
}
6058

6159
void v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name)
@@ -92,6 +90,8 @@ void v8js_commonjs_normalise_identifier(char *base, char *identifier, char *norm
9290
*module_name = 0;
9391

9492
strcat(module_name, normalised_terms.back());
93+
94+
efree(normalised_terms.back());
9595
normalised_terms.pop_back();
9696

9797
for (std::vector<char *>::iterator it = normalised_terms.begin(); it != normalised_terms.end(); it++) {

0 commit comments

Comments
 (0)