From e81047b90678ab7053f93e870b7249f5bfb77b9c Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Thu, 26 Sep 2019 22:19:28 -0600 Subject: [PATCH] Fix a segfault related to async statements --- dbdimp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index c88321f8..73a67120 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -684,6 +684,8 @@ void dbd_db_destroy (SV * dbh, imp_dbh_t * imp_dbh) if (imp_dbh->async_sth->result) { TRACE_PQCLEAR; PQclear(imp_dbh->async_sth->result); + if (imp_dbh->last_result == imp_dbh->async_sth->result) + imp_dbh->last_result = NULL; } imp_dbh->async_sth = NULL; } @@ -5169,8 +5171,13 @@ long pg_db_result (SV *h, imp_dbh_t *imp_dbh) if (imp_dbh->async_sth) { if (imp_dbh->async_sth->result) { /* For potential multi-result sets */ - TRACE_PQCLEAR; - PQclear(imp_dbh->async_sth->result); + if (imp_dbh->sth_result_owner == (long int)imp_dbh->async_sth) { + imp_dbh->sth_result_owner = 0; + } + else { + TRACE_PQCLEAR; + PQclear(imp_dbh->async_sth->result); + } } imp_dbh->async_sth->result = result; }