diff options
| author | Dmitry Stogov <dmitry@zend.com> | 2015-07-01 22:17:08 +0300 |
|---|---|---|
| committer | Dmitry Stogov <dmitry@zend.com> | 2015-07-01 22:17:08 +0300 |
| commit | 887e5ad110eb87c3969b0e7f12a2b2fd9fb9c0b0 (patch) | |
| tree | e623041667a9551caeecf93b679d0b53609dc5cf | |
| parent | d2d326a381d99fdf148ea30e2d96a7b525e35d9f (diff) | |
| download | php-git-887e5ad110eb87c3969b0e7f12a2b2fd9fb9c0b0.tar.gz | |
Cleanup (avoid reallocation)
| -rw-r--r-- | ext/standard/iptc.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 929d495023..4554be32db 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; } |
