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
Merge branch 'PHP-5.4' into PHP-5.5

* PHP-5.4:
  Improves fix for memory leak, keep in sync with upstream.
fix merge
Merge branch 'PHP-5.6'

* PHP-5.6:
  Improves fix for memory leak, keep in sync with upstream.