File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ void finalizer_wrapper(SEXP p) {
3636 if (TYPEOF (p) == EXTPTRSXP) {
3737 T* ptr = (T*) R_ExternalPtrAddr (p);
3838 RCPP_DEBUG_3 (" finalizer_wrapper<%s>(SEXP p = <%p>). ptr = %p" , DEMANGLE (T), p, ptr)
39+
40+ // Clear before finalizing to avoid interesting behavior,
41+ // e.g. https://github.com/r-dbi/RPostgres/issues/167
42+ R_ClearExternalPtr (p);
43+
3944 Finalizer (ptr);
4045 }
4146}
@@ -174,10 +179,10 @@ class XPtr :
174179 // Call the finalizer -- note that this implies that finalizers
175180 // need to be ready for a NULL external pointer value (our
176181 // default C++ finalizer is since delete NULL is a no-op).
182+ // This clears the external pointer just before calling the finalizer,
183+ // to avoid interesting behavior with co-dependent finalizers,
184+ // e.g. https://github.com/r-dbi/RPostgres/issues/167.
177185 finalizer_wrapper<T,Finalizer>(Storage::get__ ());
178-
179- // Clear the external pointer
180- R_ClearExternalPtr (Storage::get__ ());
181186 }
182187 }
183188
You can’t perform that action at this time.
0 commit comments