Skip to content

Commit edae243

Browse files
Su, Taoiluuu1994
Su, Tao
authored andcommitted
Fix GH-10755: Memory leak in phar_rename_archive()
In phar_renmae_archive() context, added one reference but immediately destroyed another, so do not need to increase refcount. With removal of refcount++ line, PHP/Zend no longer reports memory leak. Updated bug69958.phpt test file accordingly. Closes GH-10856
1 parent 5efd60e commit edae243

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ PHP NEWS
9898
. pg_fetch_object raises a ValueError instead of an Exception.
9999
(David Carlier)
100100

101+
- Phar:
102+
. Fix memory leak in phar_rename_archive(). (stkeke)
103+
101104
- Posix:
102105
. Added posix_sysconf. (David Carlier)
103106
. Added posix_pathconf. (David Carlier)

ext/phar/phar_object.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2113,10 +2113,12 @@ static zend_object *phar_rename_archive(phar_archive_data **sphar, char *ext) /*
21132113
pphar->flags = phar->flags;
21142114
pphar->fp = phar->fp;
21152115
phar->fp = NULL;
2116+
/* FIX: GH-10755 Double-free issue caught by ASAN check */
2117+
pphar->alias = phar->alias; /* Transfer alias to pphar to */
2118+
phar->alias = NULL; /* avoid being free'd twice */
21162119
phar_destroy_phar_data(phar);
21172120
*sphar = NULL;
21182121
phar = pphar;
2119-
phar->refcount++;
21202122
newpath = oldpath;
21212123
goto its_ok;
21222124
}

ext/phar/tests/bug69958.phpt

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Phar: bug #69958: Segfault in Phar::convertToData on invalid file
3-
--XFAIL--
4-
Still has memory leaks, see https://bugs.php.net/bug.php?id=70005
53
--EXTENSIONS--
64
phar
75
--FILE--
@@ -10,8 +8,8 @@ $tarphar = new PharData(__DIR__.'/bug69958.tar');
108
$phar = $tarphar->convertToData(Phar::TAR);
119
?>
1210
--EXPECTF--
13-
Fatal error: Uncaught BadMethodCallException: phar "%s/bug69958.tar" exists and must be unlinked prior to conversion in %s/bug69958.php:%d
11+
Fatal error: Uncaught BadMethodCallException: phar "%sbug69958.tar" exists and must be unlinked prior to conversion in %sbug69958.php:%d
1412
Stack trace:
15-
#0 %s/bug69958.php(%d): PharData->convertToData(%d)
13+
#0 %sbug69958.php(%d): PharData->convertToData(%d)
1614
#1 {main}
17-
thrown in %s/bug69958.php on line %d
15+
thrown in %sbug69958.php on line %d

0 commit comments

Comments
 (0)