]> granicus.if.org Git - php/commitdiff
Some OCI8 fixes (Rajendra)
authorChristopher Jones <christopher.jones@oracle.com>
Mon, 13 Jul 2015 01:50:00 +0000 (11:50 +1000)
committerChristopher Jones <christopher.jones@oracle.com>
Mon, 13 Jul 2015 01:50:00 +0000 (11:50 +1000)
ext/oci8/oci8.c
ext/oci8/oci8_interface.c
ext/oci8/oci8_statement.c

index f431dcaba9a7775b69298f11aee36e190904c5f3..e3ec34f578b1af5c0fe9f3158ed956e6ae9c9cd3 100644 (file)
@@ -1453,14 +1453,16 @@ static void php_oci_pconnection_list_np_dtor(zend_resource *entry)
                OCI_G(in_call)) {
 
                /* Remove the hash entry if present */
-               zvp = zend_hash_find(&EG(persistent_list), connection->hash_key);
-               le = Z_RES_P(zvp);              /* PHPNG TODO check for null zvp */
-               if (le != NULL && le->type == le_pconnection && le->ptr == connection) {
-                       zend_hash_del(&EG(persistent_list), connection->hash_key);
-               }
-               else {
-                       php_oci_connection_close(connection);
-                       OCI_G(num_persistent)--;
+               if (connection->hash_key) {
+                       zvp = zend_hash_find(&EG(persistent_list), connection->hash_key);
+                       le = zvp ? Z_RES_P(zvp) : NULL;         /* PHPNG TODO check for null zvp */
+                       if (le != NULL && le->type == le_pconnection && le->ptr == connection) {
+                               zend_hash_del(&EG(persistent_list), connection->hash_key);
+                       }
+                       else {
+                               php_oci_connection_close(connection);
+                               OCI_G(num_persistent)--;
+                       }
                }
 
 #ifdef HAVE_OCI8_DTRACE
@@ -1540,6 +1542,8 @@ void php_oci_define_hash_dtor(zval *data)
                efree(define->name);
                define->name = NULL;
        }
+
+    efree(define);
 }
 /* }}} */
 
@@ -1562,6 +1566,7 @@ void php_oci_bind_hash_dtor(zval *data)
        if (bind->array.indicators) {
                efree(bind->array.indicators);
        }
+
        efree(bind);
        /*zval_ptr_dtor(&bind->zval); */
 }
@@ -1579,7 +1584,7 @@ void php_oci_column_hash_dtor(zval *data)
                zend_list_close(column->stmtid);
        }
 
-       if (column->is_descr) {
+       if (column->descid) {
                zend_list_close(column->descid);
        }
 
@@ -1946,7 +1951,6 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
                        le = Z_RES_P(zvp);
                        found = 1;
                        if (le->type == le_index_ptr) {
-                               int type, link;
                                void *ptr;
 
                                ptr = le->ptr; /* PHPNG TODO */
@@ -1984,7 +1988,6 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
                        if (connection->is_open) {
                                /* found an open connection. now ping it */
                                if (connection->is_persistent) {
-                                       int rsrc_type;
 
                                        /* Check connection liveness in the following order:
                                         * 1) always check OCI_ATTR_SERVER_STATUS
@@ -2008,7 +2011,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
                                                        connection->used_this_request = 1;
                                                        tmp = (php_oci_connection *)connection->id->ptr;
 
-                                                       if (tmp != NULL && rsrc_type == le_pconnection && tmp->hash_key->len == hashed_details.s->len &&
+                                                       if (tmp != NULL && tmp->hash_key->len == hashed_details.s->len &&
                                                                memcmp(tmp->hash_key->val, hashed_details.s->val, tmp->hash_key->len) == 0 && ++GC_REFCOUNT(connection->id) == SUCCESS) {
                                                                /* do nothing */
                                                        } else {
@@ -2039,7 +2042,6 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
                         * if ping fails
                         */
                        if (persistent){
-                               int rsrc_type;
 
                                connection->is_open = 0;
                                connection->used_this_request = 1;
@@ -2047,7 +2049,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
                                /* We have to do a hash_del but need to preserve the resource if there is a positive
                                 * refcount. Set the data pointer in the list entry to NULL
                                 */
-                               if (connection == connection->id->ptr && rsrc_type == le_pconnection) {
+                               if (connection == connection->id->ptr) {
                                        le->ptr = NULL;
                                }
 
@@ -2369,14 +2371,17 @@ static int php_oci_connection_close(php_oci_connection *connection)
         * (like env) on the session pool
         */
                php_oci_spool_close(connection->private_spool);
+               connection->private_spool = NULL;
        }
 
        if (connection->hash_key) {
                pefree(connection->hash_key, connection->is_persistent);
+               connection->hash_key = NULL;
        }
 #ifdef HAVE_OCI8_DTRACE
        if (connection->client_id) {
                pefree(connection->client_id, connection->is_persistent);
+               connection->client_id = NULL;
        }
 #endif /* HAVE_OCI8_DTRACE */
        pefree(connection, connection->is_persistent);
@@ -2568,12 +2573,11 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode)
        } else if (column->is_descr) {
 
                if (column->data_type != SQLT_RDD) {
-                       int rsrc_type;
 
                        /* reset descriptor's length */
                        descriptor = (php_oci_descriptor *) column->descid->ptr;
 
-                       if (!descriptor || rsrc_type != le_descriptor) {
+                       if (!descriptor) {
                                php_error_docref(NULL, E_WARNING, "Unable to find LOB descriptor #%d", column->descid);
                                return 1;
                        }
@@ -2972,7 +2976,7 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
 {
        smart_str spool_hashed_details = {0};
        php_oci_spool *session_pool = NULL;
-       zend_resource spool_le = {0};
+       zend_resource spool_le = {{0}};
        zend_resource *spool_out_le = NULL;
        zend_bool iserror = 0;
        zval *spool_out_zv = NULL;
index bccab92a482a30a5956beac6384d145f19e2a308..ce6ee0a3aafb995847cbba7128f1fd37cdaa22e2 100644 (file)
@@ -54,7 +54,7 @@ PHP_FUNCTION(oci_define_by_name)
        size_t name_len;
        zend_long type = 0;
        php_oci_statement *statement;
-       php_oci_define *define, *tmp_define;
+       php_oci_define *define;
        zend_string *zvtmp;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsz/|l", &stmt, &name, &name_len, &var, &type) == FAILURE) {
@@ -77,10 +77,8 @@ PHP_FUNCTION(oci_define_by_name)
 
        /* if (zend_hash_add(statement->defines, name, name_len, define, sizeof(php_oci_define), (void **)&tmp_define) == SUCCESS) { */
        zvtmp = zend_string_init(name, name_len, 0);
-       if ((tmp_define = zend_hash_add_new_ptr(statement->defines, zvtmp, define)) != NULL) {
-               efree(define);
+       if ((define = zend_hash_add_new_ptr(statement->defines, zvtmp, define)) != NULL) {
                zend_string_release(zvtmp);
-               define = tmp_define;
        } else {
                efree(define);
                zend_string_release(zvtmp);
@@ -90,8 +88,8 @@ PHP_FUNCTION(oci_define_by_name)
        define->name = (text*) estrndup(name, name_len);
        define->name_len = name_len;
        define->type = type;
-       memmove(&define->zval, var, sizeof(zval));
-       Z_ADDREF_P(var);
+       /* convert_to_string(var); */
+       ZVAL_COPY(&define->zval, var);
 
        RETURN_TRUE;
 }
@@ -1699,6 +1697,7 @@ PHP_FUNCTION(oci_num_fields)
    Parse a SQL or PL/SQL statement and return a statement resource */
 PHP_FUNCTION(oci_parse)
 {
+       zval *z_statement;
        zval *z_connection;
        php_oci_connection *connection;
        php_oci_statement *statement;
@@ -1714,6 +1713,7 @@ PHP_FUNCTION(oci_parse)
        statement = php_oci_statement_create(connection, query, query_len);
 
        if (statement) {
+               GC_REFCOUNT(statement->id)++;
                RETURN_RES(statement->id);
        }
        RETURN_FALSE;
index 3f5e826a7bb442395c2c29309c1eb186674595cf..b007cce428bd5930214d4af71b055dfd0d468c27 100644 (file)
@@ -166,8 +166,8 @@ php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement)
                statement2->has_descr = 0;
                statement2->stmttype = 0;
 
-               Z_ADDREF_P(statement->id);
-               Z_ADDREF_P(statement2->connection->id);
+               GC_REFCOUNT(statement->id)++;
+               GC_REFCOUNT(statement2->connection->id)++;
 
                php_oci_statement_set_prefetch(statement2, statement->prefetch_count);
                
@@ -1086,7 +1086,7 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len,
        /* dvoid *php_oci_collection               = NULL; */
        OCIStmt *oci_stmt                               = NULL;
        dvoid *bind_data                                = NULL;
-       php_oci_bind bind, *old_bind, *bindp;
+       php_oci_bind *old_bind, *bindp;
        int mode = OCI_DATA_AT_EXEC;
        sb4 value_sz = -1;
        sword errstatus;
@@ -1226,7 +1226,6 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, int name_len,
        bindp->parent_statement = statement;
        ZVAL_COPY(&bindp->zval, var);
        bindp->type = type;
-       Z_TRY_ADDREF_P(var);
        
        PHP_OCI_CALL_RETURN(errstatus,
                OCIBindByName,
@@ -1411,12 +1410,17 @@ sb4 php_oci_bind_out_callback(
                convert_to_string(val);
                zval_dtor(val);
 
-#if 0          
+               {
+                       char *p = ecalloc(1, PHP_OCI_PIECE_SIZE);
+                       ZVAL_STRINGL(val, p, PHP_OCI_PIECE_SIZE);
+                       efree(p);
+               }
+#if 0
                Z_STRLEN_P(val) = PHP_OCI_PIECE_SIZE; /* 64K-1 is max XXX */
-               Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(phpbind->zval) + 1);
+               Z_STRVAL_P(val) = ecalloc(1, Z_STRLEN_P(val) + 1);
                /* XXX is this right? */
-#endif         
                ZVAL_STRINGL(val, NULL, Z_STRLEN(phpbind->zval) + 1);
+#endif         
 
                /* XXX we assume that zend-zval len has 4 bytes */
                *alenpp = (ub4*) &Z_STRLEN(phpbind->zval);
@@ -1592,7 +1596,6 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, int nam
        bindp->array.type = type;
        bindp->indicator = 0;           /* not used for array binds */
        bindp->type = 0;                        /* not used for array binds */
-
        Z_ADDREF_P(var);
 
        PHP_OCI_CALL_RETURN(errstatus,