Skip to content

Commit 0dce4be

Browse files
committed
Fixed LOB mem leak reported on gcov. Also fixed unsigend comparison compile warning; and remove direct field access
1 parent 3c32019 commit 0dce4be

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ PHP NEWS
1010
. Fixed bug #70898, #70895 (null ptr deref and segfault with crafted callable).
1111
(Anatol, Laruence)
1212

13+
- OCI8:
14+
. Fixed memory leak with LOBs. (Senthil)
15+
1316
- SOAP:
1417
. Fixed bug #70900 (SoapClient systematic out of memory error). (Dmitry)
1518

ext/oci8/oci8.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ static void php_oci_pconnection_list_np_dtor(zend_resource *entry)
14521452
/* Remove the hash entry if present */
14531453
if (connection->hash_key) {
14541454
zvp = zend_hash_find(&EG(persistent_list), connection->hash_key);
1455-
le = zvp ? Z_RES_P(zvp) : NULL; /* PHPNG TODO check for null zvp */
1455+
le = zvp ? Z_RES_P(zvp) : NULL;
14561456
if (le != NULL && le->type == le_pconnection && le->ptr == connection) {
14571457
zend_hash_del(&EG(persistent_list), connection->hash_key);
14581458
}
@@ -1927,13 +1927,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
19271927
}
19281928

19291929
/* make it lowercase */
1930-
/* PHPNG TODO is this safe to do? What about interned strings? */
1931-
php_strtolower(hashed_details.s->val, hashed_details.s->len);
1930+
php_strtolower(ZSTR_VAL(hashed_details.s), ZSTR_LEN(hashed_details.s));
19321931

19331932
if (!exclusive && !new_password) {
19341933
zend_bool found = 0;
19351934

1936-
/* PHPNG TODO Check hashed_details is used correctly */
19371935
if (persistent && ((zvp = zend_hash_find(&EG(persistent_list), hashed_details.s))) != NULL) {
19381936
zend_resource *le = Z_RES_P(zvp);
19391937

@@ -1948,7 +1946,7 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
19481946
if (le->type == le_index_ptr) {
19491947
zend_resource *ptr;
19501948

1951-
ptr = (zend_resource *) le->ptr; /* PHPNG TODO */
1949+
ptr = (zend_resource *) le->ptr;
19521950
if (ptr && (ptr->type == le_connection)) {
19531951
connection = (php_oci_connection *)ptr->ptr;
19541952
}
@@ -2011,8 +2009,8 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
20112009
}
20122010

20132011
if ((tmp_val != NULL) && (tmp != NULL) &&
2014-
(tmp->hash_key->len == hashed_details.s->len) &&
2015-
(memcmp(tmp->hash_key->val, hashed_details.s->val, tmp->hash_key->len) == 0)) {
2012+
(ZSTR_LEN(tmp->hash_key) == ZSTR_LEN(hashed_details.s)) &&
2013+
(memcmp(ZSTR_VAL(tmp->hash_key), ZSTR_VAL(hashed_details.s), ZSTR_LEN(tmp->hash_key)) == 0)) {
20162014
connection = tmp;
20172015
++GC_REFCOUNT(connection->id);
20182016
/* do nothing */
@@ -2866,7 +2864,7 @@ static php_oci_spool *php_oci_create_spool(char *username, int username_len, cha
28662864
}
28672865

28682866
/* Populate key if passed */
2869-
if (hash_key && hash_key->val) {
2867+
if (hash_key && (ZSTR_LEN(hash_key) > 0)) {
28702868
session_pool->spool_hash_key = zend_string_dup(hash_key, 1);
28712869
if (session_pool->spool_hash_key == NULL) {
28722870
iserror = 1;
@@ -3022,8 +3020,7 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
30223020
/* Session Pool Hash Key : oci8spool***username**edition**hashedpassword**dbname**charset */
30233021

30243022
smart_str_0(&spool_hashed_details);
3025-
/* PHPNG TODO is this safe to do? */
3026-
php_strtolower(spool_hashed_details.s->val, spool_hashed_details.s->len);
3023+
php_strtolower(ZSTR_VAL(spool_hashed_details.s), ZSTR_LEN(spool_hashed_details.s));
30273024
/* }}} */
30283025

30293026
spool_out_zv = zend_hash_find(&EG(persistent_list), spool_hashed_details.s);
@@ -3044,8 +3041,8 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
30443041
PHP_OCI_REGISTER_RESOURCE(session_pool, le_psessionpool);
30453042
zend_hash_update_mem(&EG(persistent_list), session_pool->spool_hash_key, (void *)&spool_le, sizeof(zend_resource));
30463043
} else if (spool_out_le->type == le_psessionpool &&
3047-
((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key->len == spool_hashed_details.s->len &&
3048-
memcmp(((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key->val, spool_hashed_details.s->val, spool_hashed_details.s->len) == 0) {
3044+
ZSTR_LEN(((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key) == ZSTR_LEN(spool_hashed_details.s) &&
3045+
memcmp(ZSTR_VAL(((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key), ZSTR_VAL(spool_hashed_details.s), ZSTR_LEN(spool_hashed_details.s)) == 0) {
30493046
/* retrieve the cached session pool */
30503047
session_pool = (php_oci_spool *)(spool_out_le->ptr);
30513048
}

ext/oci8/oci8_lob.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, zend_lon
109109
return NULL;
110110
}
111111

112-
zend_hash_index_update_ptr(connection->descriptors, descriptor->index, &descriptor);
112+
zend_hash_index_update_ptr(connection->descriptors, descriptor->index, descriptor);
113113
}
114114
return descriptor;
115115

@@ -666,11 +666,11 @@ void php_oci_lob_free (php_oci_descriptor *descriptor)
666666
}
667667

668668
if (descriptor->connection->descriptors) {
669-
/* delete descriptor from the hash */
670-
zend_hash_index_del(descriptor->connection->descriptors, descriptor->index);
671669
if (zend_hash_num_elements(descriptor->connection->descriptors) == 0) {
672670
descriptor->connection->descriptor_count = 0;
673671
} else {
672+
/* delete descriptor from the hash */
673+
zend_hash_index_del(descriptor->connection->descriptors, descriptor->index);
674674
if (descriptor->index + 1 == descriptor->connection->descriptor_count) {
675675
/* If the descriptor being freed is the end-most one
676676
* allocated, then the descriptor_count is reduced so

0 commit comments

Comments
 (0)