diff options
author | Philip Hofstetter <phofstetter@sensational.ch> | 2015-06-03 14:56:02 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2015-06-10 16:36:00 +0200 |
commit | 9ba3a4c66ab781763547923d7d8fb15f0962fc63 (patch) | |
tree | ffb87d5f4cdd00c962301ee995c75f23ad569464 /ext/pdo_pgsql/pgsql_statement.c | |
parent | f14141aca2eb675c8f5b0dc246ec4f04b0271218 (diff) | |
download | php-git-9ba3a4c66ab781763547923d7d8fb15f0962fc63.tar.gz |
fix memory leak in pdo_pgsql closeCursor (bug 69752)
the parent PDO closeCursor method resets the pdo_stmt_t's executed flag
which is used by the postgres driver as a flag to check whether to
allocate memory for the column data or not.
This means that after the parent closeCursor() has been called, the
pdo_pgsql driver will allocate a new buffer for the columns, so the
existing buffer should be freed when the cursor is being closed.
Diffstat (limited to 'ext/pdo_pgsql/pgsql_statement.c')
-rw-r--r-- | ext/pdo_pgsql/pgsql_statement.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index f541c86259..75c5a4a041 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -220,7 +220,7 @@ stmt_retry: return 0; } - if (!stmt->executed && !stmt->column_count) { + if (!stmt->executed && (!stmt->column_count || S->cols == NULL)) { stmt->column_count = (int) PQnfields(S->result); S->cols = ecalloc(stmt->column_count, sizeof(pdo_pgsql_column)); } @@ -614,6 +614,12 @@ done: static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC) { + pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; + + if (S->cols != NULL){ + efree(S->cols); + S->cols = NULL; + } return 1; } |