The `allocate_weakref` may return NULL when out of memory. We need to
handle that case and propagate the error.
(cherry picked from commit
a640a605a8a1a3f73b98f948d0c2a7d42134f692)
Co-authored-by: Sam Gross <colesbury@gmail.com>
return basic_ref;
}
PyWeakReference *newref = allocate_weakref(type, obj, callback);
+ if (newref == NULL) {
+ UNLOCK_WEAKREFS(obj);
+ return NULL;
+ }
insert_weakref(newref, list);
UNLOCK_WEAKREFS(obj);
return newref;
else {
// We may not be able to safely allocate inside the lock
PyWeakReference *newref = allocate_weakref(type, obj, callback);
+ if (newref == NULL) {
+ return NULL;
+ }
LOCK_WEAKREFS(obj);
insert_weakref(newref, list);
UNLOCK_WEAKREFS(obj);