Skip to content

Commit 6bddd01

Browse files
Fix componentize::GetMemBuffer (#184)
This patch fixes an issue where if the return value of `sbrk(0)` ever changed after initially being set, we'd encounter a panic: the value is stored in a `PersistentRootedObject`, `AB`, which the code tries to initialize multiple times. Persistent roots can't only be initialized ones, after which they have to be `set`.
1 parent 16f6b86 commit 6bddd01

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

embedding/embedding.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ bool ReportAndClearException(JSContext *cx) {
490490
return true;
491491
}
492492

493-
void *LAST_SBRK;
493+
void *LAST_SBRK = nullptr;
494494
JS::PersistentRootedObject AB;
495495
static bool GetMemBuffer(JSContext *cx, unsigned argc, JS::Value *vp) {
496496
if (sbrk(0) != LAST_SBRK) {
@@ -502,7 +502,7 @@ static bool GetMemBuffer(JSContext *cx, unsigned argc, JS::Value *vp) {
502502
#endif
503503
JS::RootedObject mem_buffer(cx, JS::NewArrayBufferWithUserOwnedContents(
504504
cx, (size_t)LAST_SBRK, base));
505-
AB.init(cx, mem_buffer);
505+
AB.set(mem_buffer);
506506
}
507507
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
508508
args.rval().setObject(*AB);
@@ -512,6 +512,7 @@ static bool GetMemBuffer(JSContext *cx, unsigned argc, JS::Value *vp) {
512512
bool install(api::Engine *engine) {
513513
Runtime.engine = engine;
514514
Runtime.cx = engine->cx();
515+
AB.init(engine->cx());
515516

516517
char env_name[100];
517518

0 commit comments

Comments
 (0)