kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit a431f762639d587c4b141a5442cced7039608dbb
parent 6eb091c77ce5bf5238567b29290ae57c5ce384fe
Author: Joris Vink <joris@coders.se>
Date:   Mon, 31 Mar 2014 01:09:08 +0200

pgsql_conn improvements.

set conn inside kore_pgsql to NULL when we've completed.
if at kore_pgsql_cleanup() time the conn is still there
we'll drain it as per documentation.

Diffstat:
contrib/postgres/kore_pgsql.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/contrib/postgres/kore_pgsql.c b/contrib/postgres/kore_pgsql.c @@ -165,8 +165,9 @@ kore_pgsql_continue(struct http_request *req, int i) case KORE_PGSQL_STATE_WAIT: break; case KORE_PGSQL_STATE_DONE: - req->pgsql[i]->state = KORE_PGSQL_STATE_COMPLETE; + req->pgsql[i]->conn = NULL; req->flags &= ~HTTP_REQUEST_SLEEPING; + req->pgsql[i]->state = KORE_PGSQL_STATE_COMPLETE; kore_mem_free(conn->job->query); kore_mem_free(conn->job); @@ -190,7 +191,8 @@ kore_pgsql_continue(struct http_request *req, int i) void kore_pgsql_cleanup(struct http_request *req) { - int i; + int i; + struct pgsql_conn *conn; for (i = 0; i < HTTP_PGSQL_MAX; i++) { if (req->pgsql[i] == NULL) @@ -204,6 +206,12 @@ kore_pgsql_cleanup(struct http_request *req) if (req->pgsql[i]->error != NULL) kore_mem_free(req->pgsql[i]->error); + if (req->pgsql[i]->conn != NULL) { + conn = req->pgsql[i]->conn; + while (PQgetResult(conn->db) != NULL) + ; + } + kore_mem_free(req->pgsql[i]); req->pgsql[i] = NULL; }