Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inner functions' variables are freed #67

Open
Naheel-Azawy opened this issue May 8, 2020 · 3 comments
Open

Inner functions' variables are freed #67

Naheel-Azawy opened this issue May 8, 2020 · 3 comments
Labels

Comments

@Naheel-Azawy
Copy link

Having the following js:

function foo() {
    var s = "a";
    function bar(a) {
        s += " hello " + a;
    }
    bar(5);
    return s;
}
console.log(foo());

The expected result is of course a hello 5. However, when checking the c code:

...
void bar(int16_t a, const char ** s)
{
    char * tmp_result_2 = NULL;
    char * tmp_result = NULL;
    tmp_result_2 = malloc(strlen(" hello ") + STR_INT16_T_BUFLEN + 1);
    assert(tmp_result_2 != NULL);
    tmp_result_2[0] = '\0';
    strcat(tmp_result_2, " hello ");
    str_int16_t_cat(tmp_result_2, a);
    tmp_result = malloc(strlen(*s) + strlen(tmp_result_2) + 1);
    assert(tmp_result != NULL);
    tmp_result[0] = '\0';
    strcat(tmp_result, *s);
    strcat(tmp_result, tmp_result_2);
    (*s = tmp_result);
    free((char *)tmp_result); // <===== This should not be freed here!!!
    free((char *)tmp_result_2);
}
const char * foo()
{
    const char * s;
    s = "a";
    bar(5, &s);
    return s;
}
...
@andrei-markeev
Copy link
Owner

true. thanks for reporting! 👍
will fix

@bil-ash
Copy link

bil-ash commented Dec 3, 2020

@andrei-markeev Any ETA of the fix? Multiple issues in this repo have been created which are actually manifestations of (this) same bug. Please fix this soon.

@andrei-markeev
Copy link
Owner

@bil-ash, nope, no ETAs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants