diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index 93126c6a5da30fc3cda950289a581a9145920b78..2d37c6b194be4ca88507c4a77237f4e094782cdd 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -733,6 +733,7 @@ static int update_pgsql(const char *database, const char *tablename, const char
 	ast_mutex_lock(&pgsql_lock);
 	if (!pgsql_reconnect(database)) {
 		ast_mutex_unlock(&pgsql_lock);
+		release_table(table);
 		return -1;
 	}
 
@@ -878,6 +879,7 @@ static int update2_pgsql(const char *database, const char *tablename, const stru
 	ast_mutex_lock(&pgsql_lock);
 	if (!pgsql_reconnect(database)) {
 		ast_mutex_unlock(&pgsql_lock);
+		release_table(table);
 		return -1;
 	}
 
@@ -1322,6 +1324,7 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
 
 			        if (pgsql_exec(database, tablename, ast_str_buffer(sql), &result) != 0) {
 					ast_mutex_unlock(&pgsql_lock);
+					release_table(table);
 				        return -1;
 			        }