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

Modifying prototype causes memory leak (assertion in JS_FreeRuntime) #66

Closed
jesse-k opened this issue May 24, 2021 · 2 comments
Closed

Comments

@jesse-k
Copy link

jesse-k commented May 24, 2021

The following self-contained test code:

#include <string>
#include "quickjs.h"

int main() {
    auto runtime = JS_NewRuntime();
    auto context = JS_NewContext(runtime);

    std::string source =
        "function foo() {}\n"
        "foo.prototype.bar = function() {};";
    JS_Eval(context, source.c_str(), source.size(), "", JS_EVAL_TYPE_GLOBAL);

    JS_FreeContext(context);
    JS_FreeRuntime(runtime);
}

Produces the following error for me:

Assertion failed: (list_empty(&rt->gc_obj_list)), function JS_FreeRuntime

If I use 'DUMP_LEAKS', I get:

Object leaks:
       ADDRESS REFS SHRF          PROTO      CLASS PROPS
   0x1071d4bc0    1   0*    0x1071c5510   Function { length: 0, name: 14'', prototype: [autoinit 0x1071c4e80 0 0x0] }

This issue seems similar, but I don't know if it's the same. It's of course possible this is user error and I'm misusing the API somehow.

My development environment is macOS 11.3, Xcode 12.5. I get the same results whether I use the makefile and the resulting static library or include the relevant QuickJS source files directly in an Xcode project. Also, interestingly I don't get the leak if I use qjsc to generate bytecode and then load the bytecode - it only happens if I load the source code directly.

@ghost
Copy link

ghost commented May 29, 2021

JS_Eval returns a JSValue, which should be freed with JS_FreeValue.

@jesse-k
Copy link
Author

jesse-k commented May 29, 2021

JS_Eval returns a JSValue, which should be freed with JS_FreeValue.

Got it, thanks.

@jesse-k jesse-k closed this as completed May 29, 2021
GerHobbelt pushed a commit to GerHobbelt/quickjs that referenced this issue Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant