com php-src: Cleanup (avoid reallocation): ext/standard/iptc.c

From: Date: Wed, 01 Jul 2015 19:17:08 +0000
Subject: com php-src: Cleanup (avoid reallocation): ext/standard/iptc.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87672@lists.php.net to get a copy of this message
Commit: 887e5ad110eb87c3969b0e7f12a2b2fd9fb9c0b0 Author: Dmitry Stogov <dmitry@zend.com> Wed, 1 Jul 2015 22:17:08 +0300 Parents: d2d326a381d99fdf148ea30e2d96a7b525e35d9f Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=887e5ad110eb87c3969b0e7f12a2b2fd9fb9c0b0 Log: Cleanup (avoid reallocation) Changed paths: M ext/standard/iptc.c Diff: diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 929d495..4554be3 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -183,7 +183,8 @@ PHP_FUNCTION(iptcembed) FILE *fp; unsigned int marker, done = 0; int inx; - unsigned char *spoolbuf = NULL, *poi = NULL; + zend_string *spoolbuf = NULL; + unsigned char *poi = NULL; zend_stat_t sb; zend_bool written = 0; @@ -203,14 +204,15 @@ PHP_FUNCTION(iptcembed) if (spool < 2) { zend_fstat(fileno(fp), &sb); - poi = spoolbuf = safe_emalloc(1, iptcdata_len + sizeof(psheader) + sb.st_size + 1024, 1); + spoolbuf = zend_string_alloc(iptcdata_len + sizeof(psheader) + sb.st_size + 1024, 0); + poi = (unsigned char*)ZSTR_VAL(spoolbuf); memset(poi, 0, iptcdata_len + sizeof(psheader) + sb.st_size + 1024 + 1); } if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xFF) { fclose(fp); if (spoolbuf) { - efree(spoolbuf); + zend_string_free(spoolbuf); } RETURN_FALSE; } @@ -218,7 +220,7 @@ PHP_FUNCTION(iptcembed) if (php_iptc_get1(fp, spool, poi?&poi:0) != 0xD8) { fclose(fp); if (spoolbuf) { - efree(spoolbuf); + zend_string_free(spoolbuf); } RETURN_FALSE; } @@ -285,9 +287,8 @@ PHP_FUNCTION(iptcembed) fclose(fp); if (spool < 2) { - // TODO: avoid reallocation ??? - RETVAL_STRINGL((char *) spoolbuf, poi - spoolbuf); - efree(spoolbuf); + spoolbuf = zend_string_truncate(spoolbuf, poi - (unsigned char*)ZSTR_VAL(spoolbuf), 0); + RETURN_NEW_STR(spoolbuf); } else { RETURN_TRUE; }

« previous php.cvs (#87672) next »