mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
- Fixed memleak on SplFileInfo::getLinkTarget()
This commit is contained in:
parent
9275caf719
commit
f15d7f8b38
1 changed files with 5 additions and 2 deletions
|
@ -1132,7 +1132,7 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
|
||||||
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
|
spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
|
||||||
UChar *target;
|
UChar *target;
|
||||||
int ret, link_len, target_len;
|
int ret, link_len, target_len;
|
||||||
char *link, buff[MAXPATHLEN];
|
char *link = NULL, buff[MAXPATHLEN];
|
||||||
zend_error_handling error_handling;
|
zend_error_handling error_handling;
|
||||||
|
|
||||||
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
|
zend_replace_error_handling(EH_THROW, spl_ce_RuntimeException, &error_handling TSRMLS_CC);
|
||||||
|
@ -1144,11 +1144,14 @@ SPL_METHOD(SplFileInfo, getLinkTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SYMLINK
|
#ifdef HAVE_SYMLINK
|
||||||
ret = readlink(intern->file_name.s, buff, MAXPATHLEN-1);
|
ret = link ? readlink(link, buff, MAXPATHLEN-1) : -1;
|
||||||
#else
|
#else
|
||||||
ret = -1; /* always fail if not implemented */
|
ret = -1; /* always fail if not implemented */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (link && intern->file_name_type == IS_UNICODE) {
|
||||||
|
efree(link);
|
||||||
|
}
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable to read link %R, error: %s", intern->file_name_type, intern->file_name, strerror(errno));
|
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Unable to read link %R, error: %s", intern->file_name_type, intern->file_name, strerror(errno));
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue