Skip to content

Commit c20f00f

Browse files
committed
PHP 7 OCI8: fix bug57702.phpt regression
1 parent 9db46a3 commit c20f00f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ext/pdo_oci/oci_statement.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
} \
5252
} while(0)
5353

54-
static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob);
54+
static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLocator *lob);
5555

5656
static int oci_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */
5757
{
@@ -377,7 +377,7 @@ static int oci_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *pa
377377
* wanted to bind a lob locator into it from the query
378378
* */
379379

380-
stm = oci_create_lob_stream(stmt, (OCILobLocator*)P->thing);
380+
stm = oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)P->thing);
381381
if (stm) {
382382
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
383383
php_stream_to_zval(stm, parameter);
@@ -614,6 +614,7 @@ struct _oci_lob_env {
614614
typedef struct _oci_lob_env oci_lob_env;
615615

616616
struct oci_lob_self {
617+
zval dbh;
617618
pdo_stmt_t *stmt;
618619
pdo_oci_stmt *S;
619620
OCILobLocator *lob;
@@ -666,10 +667,14 @@ static size_t oci_blob_read(php_stream *stream, char *buf, size_t count)
666667
static int oci_blob_close(php_stream *stream, int close_handle)
667668
{
668669
struct oci_lob_self *self = (struct oci_lob_self *)stream->abstract;
669-
/* pdo_stmt_t *stmt = self->stmt; */
670+
pdo_stmt_t *stmt = self->stmt;
670671

671672
if (close_handle) {
673+
zend_object *obj = &stmt->std;
674+
672675
OCILobClose(self->E->svc, self->E->err, self->lob);
676+
zval_ptr_dtor(&self->dbh);
677+
GC_REFCOUNT(obj)--;
673678
efree(self->E);
674679
efree(self);
675680
}
@@ -709,10 +714,12 @@ static php_stream_ops oci_blob_stream_ops = {
709714
NULL
710715
};
711716

712-
static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob)
717+
static php_stream *oci_create_lob_stream(zval *dbh, pdo_stmt_t *stmt, OCILobLocator *lob)
713718
{
714719
php_stream *stm;
715720
struct oci_lob_self *self = ecalloc(1, sizeof(*self));
721+
722+
ZVAL_COPY_VALUE(&self->dbh, dbh);
716723
self->lob = lob;
717724
self->offset = 1; /* 1-based */
718725
self->stmt = stmt;
@@ -724,6 +731,10 @@ static php_stream *oci_create_lob_stream(pdo_stmt_t *stmt, OCILobLocator *lob)
724731
stm = php_stream_alloc(&oci_blob_stream_ops, self, 0, "r+b");
725732

726733
if (stm) {
734+
zend_object *obj;
735+
obj = &stmt->std;
736+
Z_ADDREF(self->dbh);
737+
GC_REFCOUNT(obj)++;
727738
return stm;
728739
}
729740

@@ -747,7 +758,7 @@ static int oci_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len
747758

748759
if (C->dtype == SQLT_BLOB || C->dtype == SQLT_CLOB) {
749760
if (C->data) {
750-
*ptr = (char*)oci_create_lob_stream(stmt, (OCILobLocator*)C->data);
761+
*ptr = (char*)oci_create_lob_stream(&stmt->database_object_handle, stmt, (OCILobLocator*)C->data);
751762
OCILobOpen(S->H->svc, S->err, (OCILobLocator*)C->data, OCI_LOB_READONLY);
752763
}
753764
*len = (size_t) 0;

0 commit comments

Comments
 (0)