Skip to content

Commit 4a0e50c

Browse files
committed
Avoid copy
1 parent 25dbe53 commit 4a0e50c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ext/pdo_mysql/mysql_driver.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ static zend_string* mysql_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
309309
{
310310
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
311311
bool use_national_character_set = 0;
312-
char *quoted;
313312
size_t quotedlen;
314-
zend_string *quoted_str;
315313

316314
if (H->assume_national_character_set_strings) {
317315
use_national_character_set = 1;
@@ -326,7 +324,9 @@ static zend_string* mysql_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
326324
PDO_DBG_ENTER("mysql_handle_quoter");
327325
PDO_DBG_INF_FMT("dbh=%p", dbh);
328326
PDO_DBG_INF_FMT("unquoted=%.*s", (int)ZSTR_LEN(unquoted), ZSTR_VAL(unquoted));
329-
quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3 + (use_national_character_set ? 1 : 0));
327+
328+
zend_string *quoted_str = zend_string_safe_alloc(2, ZSTR_LEN(unquoted), 3 + (use_national_character_set ? 1 : 0), false);
329+
char *quoted = ZSTR_VAL(quoted_str);
330330

331331
if (use_national_character_set) {
332332
quotedlen = mysql_real_escape_string_quote(H->server, quoted + 2, ZSTR_VAL(unquoted), ZSTR_LEN(unquoted), '\'');
@@ -343,8 +343,8 @@ static zend_string* mysql_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquo
343343
quoted[++quotedlen] = '\0';
344344
PDO_DBG_INF_FMT("quoted=%.*s", (int)quotedlen, quoted);
345345

346-
quoted_str = zend_string_init(quoted, quotedlen, 0);
347-
efree(quoted);
346+
quoted_str = zend_string_truncate(quoted_str, quotedlen, false);
347+
348348
PDO_DBG_RETURN(quoted_str);
349349
}
350350
/* }}} */

0 commit comments

Comments
 (0)