Merge remote-tracking branch 'DaveRandom/fix/txn-async-open'
[m6w6/ext-pq] / src / php_pqstm.c
index ba1203721bcbeaf547cb16b3d128bec6012965bb..7156145bcab1b053b7abaa21ed5534f0eb4273a1 100644 (file)
@@ -36,26 +36,28 @@ static void php_pqstm_object_free(void *o TSRMLS_DC)
        fprintf(stderr, "FREE stm(#%d) %p (conn(#%d): %p)\n", obj->zv.handle, obj, obj->intern->conn->zv.handle, obj->intern->conn);
 #endif
        if (obj->intern) {
-               char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
+               if (obj->intern->conn->intern) {
+                       char *quoted_name = PQescapeIdentifier(obj->intern->conn->intern->conn, obj->intern->name, strlen(obj->intern->name));
 
-               php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
+                       php_pq_callback_dtor(&obj->intern->conn->intern->onevent);
 
-               if (quoted_name) {
-                       PGresult *res;
-                       smart_str cmd = {0};
+                       if (quoted_name) {
+                               PGresult *res;
+                               smart_str cmd = {0};
 
-                       smart_str_appends(&cmd, "DEALLOCATE ");
-                       smart_str_appends(&cmd, quoted_name);
-                       smart_str_0(&cmd);
-                       PQfreemem(quoted_name);
+                               smart_str_appends(&cmd, "DEALLOCATE ");
+                               smart_str_appends(&cmd, quoted_name);
+                               smart_str_0(&cmd);
+                               PQfreemem(quoted_name);
 
-                       if ((res = PQexec(obj->intern->conn->intern->conn, cmd.c))) {
-                               PHP_PQclear(res);
+                               if ((res = PQexec(obj->intern->conn->intern->conn, cmd.c))) {
+                                       PHP_PQclear(res);
+                               }
+                               smart_str_free(&cmd);
                        }
-                       smart_str_free(&cmd);
-               }
 
-               php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+                       php_pq_object_delref(obj->intern->conn TSRMLS_CC);
+               }
                efree(obj->intern->name);
                zend_hash_destroy(&obj->intern->bound);
                if (obj->intern->params) {
@@ -183,7 +185,7 @@ static PHP_METHOD(pqstm, bind) {
                        SEPARATE_ZVAL_TO_MAKE_IS_REF(param_ref);
                        Z_ADDREF_PP(param_ref);
                        zend_hash_index_update(&obj->intern->bound, param_no, (void *) param_ref, sizeof(zval *), NULL);
-                       zend_hash_sort(&obj->intern->bound, zend_qsort, compare_index, 0 TSRMLS_CC);
+                       zend_hash_sort(&obj->intern->bound, zend_qsort, php_pq_compare_index, 0 TSRMLS_CC);
                }
        }
 }