Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0bd6527

Browse filesBrowse files
addaleaxBridgeAR
authored andcommitted
src: do not crash when accessing empty WeakRefs
Making `.incRef()` and `.decRef()` fail silently leads to better error messages when trying to access the underlying value (as opposed to crashing inside these methods). Refs: #25461 (comment) PR-URL: #29289 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Gus Caplan <me@gus.host>
1 parent fd7c2be commit 0bd6527
Copy full SHA for 0bd6527

File tree

Expand file treeCollapse file tree

1 file changed

+3
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-1
lines changed
Open diff view settings
Collapse file

‎src/node_util.cc‎

Copy file name to clipboardExpand all lines: src/node_util.cc
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ class WeakReference : public BaseObject {
191191

192192
static void IncRef(const FunctionCallbackInfo<Value>& args) {
193193
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
194-
if (weak_ref->reference_count_ == 0) weak_ref->target_.ClearWeak();
195194
weak_ref->reference_count_++;
195+
if (weak_ref->target_.IsEmpty()) return;
196+
if (weak_ref->reference_count_ == 1) weak_ref->target_.ClearWeak();
196197
}
197198

198199
static void DecRef(const FunctionCallbackInfo<Value>& args) {
199200
WeakReference* weak_ref = Unwrap<WeakReference>(args.Holder());
200201
CHECK_GE(weak_ref->reference_count_, 1);
201202
weak_ref->reference_count_--;
203+
if (weak_ref->target_.IsEmpty()) return;
202204
if (weak_ref->reference_count_ == 0) weak_ref->target_.SetWeak();
203205
}
204206

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.