diff options
| author | Andrey Hristov <andrey@php.net> | 2010-03-24 15:17:57 +0000 |
|---|---|---|
| committer | Andrey Hristov <andrey@php.net> | 2010-03-24 15:17:57 +0000 |
| commit | 293ba724517faf4d2f06d26b5ed0764f1c575bb3 (patch) | |
| tree | 4592d20c878039cc30973bf2b718123eb9c4dbe4 /ext/mysqli/mysqli_nonapi.c | |
| parent | 42c14bf473ac16d9fc15c0cf0761c465ef1729b0 (diff) | |
| download | php-git-293ba724517faf4d2f06d26b5ed0764f1c575bb3.tar.gz | |
Fix a segfault when using a mysqli object after unsuccesssful connect, the
handle should have been allocated with mysqli_init().
Diffstat (limited to 'ext/mysqli/mysqli_nonapi.c')
| -rw-r--r-- | ext/mysqli/mysqli_nonapi.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index b3b0dded08..34fec47d40 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -69,6 +69,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne zend_bool new_connection = FALSE; zend_rsrc_list_entry *le; mysqli_plist_entry *plist = NULL; + zend_bool self_alloced = 0; #if !defined(MYSQL_USE_MYSQLND) @@ -99,6 +100,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne } if (!mysql) { mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL)); + self_alloced = 1; } flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */ } else { @@ -243,6 +245,7 @@ void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_conne if (!is_real_connect) { /* free mysql structure */ mysqli_close(mysql->mysql, MYSQLI_CLOSE_DISCONNECTED); + mysql->mysql = NULL; } goto err; } @@ -292,7 +295,7 @@ err: mysql->hash_key = NULL; mysql->persistent = FALSE; } - if (!is_real_connect) { + if (!is_real_connect && self_alloced) { efree(mysql); } RETVAL_FALSE; |
