mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 23:51:51 +00:00
Use emalloc/estrdup/efree in v8js_commonjs.cc + fix memory leak
This commit is contained in:
parent
2ce7e420a7
commit
bfc6b29989
@ -24,7 +24,7 @@ extern "C" {
|
|||||||
|
|
||||||
static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms)
|
static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &terms)
|
||||||
{
|
{
|
||||||
char *term = (char *)malloc(PATH_MAX), *ptr = term;
|
char *term = (char *) emalloc(PATH_MAX), *ptr = term;
|
||||||
|
|
||||||
// Initialise the term string
|
// Initialise the term string
|
||||||
*term = 0;
|
*term = 0;
|
||||||
@ -34,7 +34,7 @@ static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &ter
|
|||||||
if (strlen(term) > 0) {
|
if (strlen(term) > 0) {
|
||||||
// Terminate term string and add to terms vector
|
// Terminate term string and add to terms vector
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
terms.push_back(strdup(term));
|
terms.push_back(estrdup(term));
|
||||||
|
|
||||||
// Reset term string
|
// Reset term string
|
||||||
memset(term, 0, strlen(term));
|
memset(term, 0, strlen(term));
|
||||||
@ -50,12 +50,10 @@ static void v8js_commonjs_split_terms(char *identifier, std::vector<char *> &ter
|
|||||||
if (strlen(term) > 0) {
|
if (strlen(term) > 0) {
|
||||||
// Terminate term string and add to terms vector
|
// Terminate term string and add to terms vector
|
||||||
*ptr++ = 0;
|
*ptr++ = 0;
|
||||||
terms.push_back(strdup(term));
|
terms.push_back(estrdup(term));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (term > 0) {
|
efree(term);
|
||||||
free(term);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void v8js_commonjs_normalise_identifier(char *base, char *identifier, char *normalised_path, char *module_name)
|
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
|
|||||||
*module_name = 0;
|
*module_name = 0;
|
||||||
|
|
||||||
strcat(module_name, normalised_terms.back());
|
strcat(module_name, normalised_terms.back());
|
||||||
|
|
||||||
|
efree(normalised_terms.back());
|
||||||
normalised_terms.pop_back();
|
normalised_terms.pop_back();
|
||||||
|
|
||||||
for (std::vector<char *>::iterator it = normalised_terms.begin(); it != normalised_terms.end(); it++) {
|
for (std::vector<char *>::iterator it = normalised_terms.begin(); it != normalised_terms.end(); it++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user