From 6510cca490880e7e91bbd51cdf916e3273eadf50 Mon Sep 17 00:00:00 2001 From: Tim Anderson Date: Thu, 1 Oct 2026 13:39:18 +1000 Subject: [PATCH] [mod_pgsql] fix memory leak --- src/mod/databases/mod_pgsql/mod_pgsql.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mod/databases/mod_pgsql/mod_pgsql.c b/src/mod/databases/mod_pgsql/mod_pgsql.c index 1a5874e14cc..0b90d863ad4 100644 --- a/src/mod/databases/mod_pgsql/mod_pgsql.c +++ b/src/mod/databases/mod_pgsql/mod_pgsql.c @@ -355,8 +355,9 @@ switch_status_t pgsql_handle_disconnect(switch_pgsql_handle_t *handle) return SWITCH_STATUS_FALSE; } - if (handle->state == SWITCH_PGSQL_STATE_CONNECTED) { + if (handle->con) { PQfinish(handle->con); + handle->con = NULL; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Disconnected from [%s]\n", handle->dsn); } switch_safe_free(handle->sql); @@ -388,8 +389,8 @@ switch_status_t pgsql_handle_connect(switch_pgsql_handle_t *handle) switch_safe_free(err_str); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to connect to the database [%s]\n", handle->dsn); - pgsql_handle_disconnect(handle); } + pgsql_handle_disconnect(handle); return SWITCH_STATUS_FALSE; } @@ -402,8 +403,8 @@ switch_status_t pgsql_handle_connect(switch_pgsql_handle_t *handle) switch_safe_free(err_str); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to setup socket for the database [%s]\n", handle->dsn); - pgsql_handle_disconnect(handle); } + pgsql_handle_disconnect(handle); return SWITCH_STATUS_FALSE; }