summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRemi Collet <remi@php.net>2014-03-04 13:41:37 +0100
committerJulien Pauli <jpauli@php.net>2014-03-05 10:52:29 +0100
commit1677be7a30e5d4bf7dd452f9a76c277238f27b6f (patch)
tree06c895a09e3bf2edd476e600af7e731cead1c996
parent61bcea70199b94d057ff60fb666a279376c8af2d (diff)
downloadphp-git-1677be7a30e5d4bf7dd452f9a76c277238f27b6f.tar.gz
Improves fix for memory leak, keep in sync with upstream.
Previous fix: http://git.php.net/?p=php-src.git;a=commitdiff;h=10eb0070700382f966bf260e44135e1f724a15d2 Upstream fix: https://github.com/glensc/file/commit/c0c0032b9e9eb57b91fefef905a3b018bab492d9
-rw-r--r--ext/fileinfo/libmagic/softmagic.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 33970e5921..82a470ac57 100644
--- a/ext/fileinfo/libmagic/softmagic.c
+++ b/ext/fileinfo/libmagic/softmagic.c
@@ -1696,11 +1696,19 @@ mget(struct magic_set *ms, const unsigned char *s, struct magic *m,
ms->o.buf = sbuf;
ms->offset = soffset;
if (rv == 1) {
- if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
- file_printf(ms, m->desc, offset) == -1)
- return -1;
- if (file_printf(ms, "%s", rbuf) == -1)
+ if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
+ file_printf(ms, m->desc, offset) == -1) {
+ if (rbuf) {
+ efree(rbuf);
+ }
+ return -1;
+ }
+ if (file_printf(ms, "%s", rbuf) == -1) {
+ if (rbuf) {
+ efree(rbuf);
+ }
return -1;
+ }
}
if (rbuf) {
efree(rbuf);