This commit is contained in:
Andrey Hristov 2006-05-10 12:29:09 +00:00
parent ac4afe552b
commit e4e7d27e4a
2 changed files with 34 additions and 18 deletions

View File

@ -69,10 +69,6 @@ void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
return;
}
if (bbuf.is_null) {
efree(bbuf.is_null);
}
for (i=0; i < bbuf.var_cnt; i++) {
/* free temporary bind buffer */
@ -89,9 +85,18 @@ void php_free_stmt_bind_buffer(BIND_BUFFER bbuf, int type)
efree(bbuf.vars);
}
/*
Don't free bbuf.is_null for FETCH_RESULT since we have allocated
is_null and buf in one block so we free only buf, which is the beginning
of the block. When FETCH_SIMPLE then buf wasn't allocated together with
buf and we have to free it.
*/
if (type == FETCH_RESULT) {
efree(bbuf.buf);
} else if (type == FETCH_SIMPLE){
efree(bbuf.is_null);
}
bbuf.var_cnt = 0;
return;
}
@ -158,16 +163,16 @@ static void mysqli_objects_destroy_object(void *object, zend_object_handle handl
efree(mysql);
my_res->ptr = NULL;
}
} else if (instanceof_function(intern->zo.ce, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt obj */
} else if (instanceof_function(intern->zo.ce, mysqli_stmt_class_entry TSRMLS_CC)) { /* stmt object */
if (my_res && my_res->ptr) {
MY_STMT *stmt = (MY_STMT *)my_res->ptr;
php_clear_stmt_bind(stmt);
}
} else if (instanceof_function(intern->zo.ce, mysqli_result_class_entry TSRMLS_CC)) { /* result obj */
} else if (instanceof_function(intern->zo.ce, mysqli_result_class_entry TSRMLS_CC)) { /* result object */
if (my_res && my_res->ptr) {
mysql_free_result(my_res->ptr);
}
} else if (instanceof_function(intern->zo.ce, mysqli_warning_class_entry TSRMLS_CC)) { /* warning obj */
} else if (instanceof_function(intern->zo.ce, mysqli_warning_class_entry TSRMLS_CC)) { /* warning object */
if (my_res && my_res->ptr) {
php_clear_warnings((MYSQLI_WARNING *)my_res->info);
}
@ -453,7 +458,7 @@ PHP_MINIT_FUNCTION(mysqli)
zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, mysqli_driver_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, mysqli_link_methods);
ce = mysqli_link_class_entry;
@ -463,7 +468,7 @@ PHP_MINIT_FUNCTION(mysqli)
REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", mysqli_warning_class_entry, mysqli_warning_methods);
ce = mysqli_warning_class_entry;
ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, mysqli_warning_property_entries);
zend_hash_add(&classes, ce->name.s, ce->name_length+1, &mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
@ -560,11 +565,14 @@ PHP_MINIT_FUNCTION(mysqli)
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_CHAR", FIELD_TYPE_CHAR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_INTERVAL", FIELD_TYPE_INTERVAL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_GEOMETRY", FIELD_TYPE_GEOMETRY, CONST_CS | CONST_PERSISTENT);
#if MYSQL_VERSION_ID > 50002
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_NEWDECIMAL", FIELD_TYPE_NEWDECIMAL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_TYPE_BIT", FIELD_TYPE_BIT, CONST_CS | CONST_PERSISTENT);
#endif
/* replication */
REGISTER_LONG_CONSTANT("MYSQLI_RPL_MASTER", MYSQL_RPL_MASTER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("MYSQLI_RPL_SLAVE", MYSQL_RPL_SLAVE, CONST_CS | CONST_PERSISTENT);

View File

@ -250,12 +250,16 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
}
bind = (MYSQL_BIND *)ecalloc(var_cnt, sizeof(MYSQL_BIND));
stmt->result.buf = (VAR_BUFFER *)ecalloc(var_cnt,sizeof(VAR_BUFFER));
stmt->result.is_null = (char *)ecalloc(var_cnt, sizeof(char));
{
int size;
char *p= emalloc(size= var_cnt * (sizeof(char) + sizeof(VAR_BUFFER)));
stmt->result.buf = (VAR_BUFFER *) p;
stmt->result.is_null = p + var_cnt * sizeof(VAR_BUFFER);
memset(p, 0, size);
}
for (i=start; i < var_cnt + start ; i++) {
ofs = i - start;
stmt->result.is_null[ofs] = 0;
col_type = (stmt->stmt->fields) ? stmt->stmt->fields[ofs].type : MYSQL_TYPE_STRING;
switch (col_type) {
@ -373,8 +377,8 @@ PHP_FUNCTION(mysqli_stmt_bind_result)
efree(stmt->result.buf[i].val);
}
}
/* Don't free stmt->result.is_null because is_null & buf are one block of memory */
efree(stmt->result.buf);
efree(stmt->result.is_null);
RETVAL_FALSE;
} else {
stmt->result.var_cnt = var_cnt;
@ -1276,6 +1280,7 @@ PHP_FUNCTION(mysqli_options)
ret = mysql_options(mysql->mysql, mysql_option, (char *)&l_value);
break;
}
RETURN_BOOL(!ret);
}
/* }}} */
@ -1295,6 +1300,7 @@ PHP_FUNCTION(mysqli_ping)
MYSQLI_FETCH_RESOURCE(mysql, MY_MYSQL *, &mysql_link, "mysqli_link", MYSQLI_STATUS_VALID);
rc = mysql_ping(mysql->mysql);
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
RETURN_BOOL(!rc);
}
/* }}} */
@ -1412,21 +1418,23 @@ PHP_FUNCTION(mysqli_real_connect)
}
if (mysql_real_connect(mysql->mysql,hostname,username,passwd,dbname,port,socket,flags) == NULL) {
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *) mysql_error(mysql->mysql) TSRMLS_CC);
php_mysqli_throw_sql_exception( mysql->mysql->net.sqlstate, mysql->mysql->net.last_errno TSRMLS_CC,
"%s", mysql->mysql->net.last_error);
/* change status */
MYSQLI_SET_STATUS(&mysql_link, MYSQLI_STATUS_INITIALIZED);
RETURN_FALSE;
}
php_mysqli_set_error(mysql_errno(mysql->mysql), (char *)mysql_error(mysql->mysql) TSRMLS_CC);
mysql->mysql->reconnect = MyG(reconnect);
/* set our own local_infile handler */
php_set_local_infile_handler_default(mysql);
/* change status */
MYSQLI_SET_STATUS(&mysql_link, MYSQLI_STATUS_VALID);
RETURN_TRUE;
@ -1531,6 +1539,7 @@ PHP_FUNCTION(mysqli_stmt_send_long_data)
}
/* }}} */
/* {{{ proto mixed mysqli_stmt_affected_rows(object stmt)
Return the number of rows affected in the last query for the given link */
PHP_FUNCTION(mysqli_stmt_affected_rows)
@ -1785,7 +1794,7 @@ PHP_FUNCTION(mysqli_stat)
/* }}} */
/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, bool mode)
/* {{{ proto int mysqli_stmt_attr_set(object stmt, long attr, long mode)
*/
PHP_FUNCTION(mysqli_stmt_attr_set)
{
@ -2073,7 +2082,6 @@ PHP_FUNCTION(mysqli_use_result)
if (MyG(report_mode) & MYSQLI_REPORT_INDEX) {
php_mysqli_report_index("from previous query", mysql->mysql->server_status TSRMLS_CC);
}
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
mysqli_resource->ptr = (void *)result;
mysqli_resource->status = MYSQLI_STATUS_VALID;