diff options
author | Dmitry Stogov <dmitry@zend.com> | 2015-07-02 19:09:37 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2015-07-02 19:09:37 +0300 |
commit | 07e646f8ffcbb896766c5df910cdb73eb6e3505f (patch) | |
tree | cb15bd2053e26d1af75ace175d2b8a4d00f6807e /ext/odbc | |
parent | 9ea98d676b0b27e68a33d872928407750270503e (diff) | |
download | php-git-07e646f8ffcbb896766c5df910cdb73eb6e3505f.tar.gz |
Cleanup (avoid reallocation)
Diffstat (limited to 'ext/odbc')
-rw-r--r-- | ext/odbc/php_odbc.c | 19 |
1 files changed, 10 insertions, 9 deletions
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: |