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) {
36
36
if (TYPEOF (p) == EXTPTRSXP) {
37
37
T* ptr = (T*) R_ExternalPtrAddr (p);
38
38
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
+
39
44
Finalizer (ptr);
40
45
}
41
46
}
@@ -174,10 +179,10 @@ class XPtr :
174
179
// Call the finalizer -- note that this implies that finalizers
175
180
// need to be ready for a NULL external pointer value (our
176
181
// 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.
177
185
finalizer_wrapper<T,Finalizer>(Storage::get__ ());
178
-
179
- // Clear the external pointer
180
- R_ClearExternalPtr (Storage::get__ ());
181
186
}
182
187
}
183
188
You can’t perform that action at this time.
0 commit comments