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.
This commit is contained in:
Joris Vink 2014-03-31 01:09:08 +02:00
parent 6eb091c77c
commit a431f76263
1 changed files with 10 additions and 2 deletions

View File

@ -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;
}