mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
fix(postgres) memory fix when connection fails sync (#21616)
### What does this PR do? We should not call .deinit() after .toJS otherwise hasPendingActivity will access invalid memory ### How did you verify your code works? Test run it with debug build on macos or asan on and will catch it --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -717,16 +717,6 @@ pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JS
|
||||
},
|
||||
};
|
||||
|
||||
ptr.updateHasPendingActivity();
|
||||
ptr.poll_ref.ref(vm);
|
||||
const js_value = ptr.toJS(globalObject);
|
||||
js_value.ensureStillAlive();
|
||||
ptr.js_value = js_value;
|
||||
|
||||
js.onconnectSetCached(js_value, globalObject, on_connect);
|
||||
js.oncloseSetCached(js_value, globalObject, on_close);
|
||||
bun.analytics.Features.postgres_connections += 1;
|
||||
|
||||
{
|
||||
const hostname = hostname_str.toUTF8(bun.default_allocator);
|
||||
defer hostname.deinit();
|
||||
@@ -761,9 +751,18 @@ pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JS
|
||||
},
|
||||
};
|
||||
}
|
||||
ptr.resetConnectionTimeout();
|
||||
}
|
||||
|
||||
// only call toJS if connectUnixAnon does not fail immediately
|
||||
ptr.updateHasPendingActivity();
|
||||
ptr.resetConnectionTimeout();
|
||||
ptr.poll_ref.ref(vm);
|
||||
const js_value = ptr.toJS(globalObject);
|
||||
js_value.ensureStillAlive();
|
||||
ptr.js_value = js_value;
|
||||
js.onconnectSetCached(js_value, globalObject, on_connect);
|
||||
js.oncloseSetCached(js_value, globalObject, on_close);
|
||||
bun.analytics.Features.postgres_connections += 1;
|
||||
return js_value;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user