Skip to content

Commit af8fa8e

Browse files
committed
Fixed bug #72294 Segmentation fault/invalid pointer in connection with pgsql_stmt_dtor
1 parent cf1ad54 commit af8fa8e

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
6262
{
6363
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
64+
zend_bool server_obj_usable = IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)])
65+
&& !(GC_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED);
6466

6567
if (S->result) {
6668
/* free the resource */
@@ -69,11 +71,11 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
6971
}
7072

7173
if (S->stmt_name) {
72-
pdo_pgsql_db_handle *H = S->H;
73-
char *q = NULL;
74-
PGresult *res;
74+
if (S->is_prepared && server_obj_usable) {
75+
pdo_pgsql_db_handle *H = S->H;
76+
char *q = NULL;
77+
PGresult *res;
7578

76-
if (S->is_prepared) {
7779
spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name);
7880
res = PQexec(H->server, q);
7981
efree(q);
@@ -106,14 +108,16 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
106108
}
107109

108110
if (S->cursor_name) {
109-
pdo_pgsql_db_handle *H = S->H;
110-
char *q = NULL;
111-
PGresult *res;
111+
if (server_obj_usable) {
112+
pdo_pgsql_db_handle *H = S->H;
113+
char *q = NULL;
114+
PGresult *res;
112115

113-
spprintf(&q, 0, "CLOSE %s", S->cursor_name);
114-
res = PQexec(H->server, q);
115-
efree(q);
116-
if (res) PQclear(res);
116+
spprintf(&q, 0, "CLOSE %s", S->cursor_name);
117+
res = PQexec(H->server, q);
118+
efree(q);
119+
if (res) PQclear(res);
120+
}
117121
efree(S->cursor_name);
118122
S->cursor_name = NULL;
119123
}

0 commit comments

Comments
 (0)