From 1ecb777d411ee2091d2bf8079ba9901bfef3c801 Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Sun, 29 Jan 2017 10:34:53 +0100 Subject: [PATCH] only remove the pgsql if it was scheduled. fixes #172. --- includes/pgsql.h | 1 + src/pgsql.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/pgsql.h b/includes/pgsql.h index 3557c65..e2f3722 100644 --- a/includes/pgsql.h +++ b/includes/pgsql.h @@ -24,6 +24,7 @@ #define KORE_PGSQL_SYNC 0x0001 #define KORE_PGSQL_ASYNC 0x0002 +#define KORE_PGSQL_SCHEDULED 0x0004 #if defined(__cplusplus) extern "C" { diff --git a/src/pgsql.c b/src/pgsql.c index 1cf6bb8..0d1942e 100644 --- a/src/pgsql.c +++ b/src/pgsql.c @@ -432,6 +432,7 @@ pgsql_schedule(struct kore_pgsql *pgsql) kore_platform_schedule_read(fd, pgsql->conn); pgsql->state = KORE_PGSQL_STATE_WAIT; + pgsql->flags |= KORE_PGSQL_SCHEDULED; } static void @@ -507,8 +508,10 @@ pgsql_conn_release(struct kore_pgsql *pgsql) /* Async query cleanup */ if (pgsql->flags & KORE_PGSQL_ASYNC) { if (pgsql->conn != NULL) { - fd = PQsocket(pgsql->conn->db); - kore_platform_disable_read(fd); + if (pgsql->flags & KORE_PGSQL_SCHEDULED) { + fd = PQsocket(pgsql->conn->db); + kore_platform_disable_read(fd); + } kore_pool_put(&pgsql_job_pool, pgsql->conn->job); } }