From: Dmitry Stogov Date: Thu, 2 Jul 2015 16:09:37 +0000 (+0300) Subject: Cleanup (avoid reallocation) X-Git-Tag: php-7.1.0alpha3~25^2~39 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=07e646f8ffcbb896766c5df910cdb73eb6e3505f;p=php Cleanup (avoid reallocation) --- diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index 49432b67cd..b5f3b97845 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -2058,6 +2058,7 @@ PHP_FUNCTION(odbc_fetch_row) PHP_FUNCTION(odbc_result) { char *field; + zend_string *field_str; int field_ind; SQLSMALLINT sql_c_type = SQL_C_CHAR; odbc_result *result; @@ -2163,25 +2164,25 @@ PHP_FUNCTION(odbc_result) } /* For char data, the length of the returned string will be longreadlen - 1 */ fieldsize = (result->longreadlen <= 0) ? 4096 : result->longreadlen; - field = emalloc(fieldsize); + field_str = zend_string_alloc(fieldsize, 0); /* SQLGetData will truncate CHAR data to fieldsize - 1 bytes and append \0. * For binary data it is truncated to fieldsize bytes. */ rc = SQLGetData(result->stmt, (SQLUSMALLINT)(field_ind + 1), sql_c_type, - field, fieldsize, &result->values[field_ind].vallen); + ZSTR_VAL(field_str), fieldsize, &result->values[field_ind].vallen); if (rc == SQL_ERROR) { odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData"); - efree(field); + zend_string_free(field_str); RETURN_FALSE; } if (result->values[field_ind].vallen == SQL_NULL_DATA) { - efree(field); + zend_string_free(field_str); RETURN_NULL(); } else if (rc == SQL_NO_DATA_FOUND) { - efree(field); + zend_string_free(field_str); RETURN_FALSE; } /* Reduce fieldlen by 1 if we have char data. One day we might @@ -2196,10 +2197,10 @@ PHP_FUNCTION(odbc_result) /* Don't duplicate result, saves one emalloc. For SQL_SUCCESS, the length is in vallen. */ - RETVAL_STRINGL(field, (rc == SQL_SUCCESS_WITH_INFO) ? fieldsize : result->values[field_ind].vallen); - // TODO: avoid dpouble reallocation ??? - efree(field); - return; + if (rc != SQL_SUCCESS_WITH_INFO) { + field_str = zend_string_truncate(field_str, result->values[field_ind].vallen, 0); + } + RETURN_NEW_STR(field_str); break; default: