Skip to content

Commit edea7a7

Browse files
committed
ext/phar: arch variable is only needed once
This removes an allocation and cleans up the logic of freeing the arch we retrieve from phar_split_fname()
1 parent e2a9232 commit edea7a7

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

ext/phar/func_interceptors.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,6 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
475475
}
476476

477477
if (!IS_ABSOLUTE_PATH(filename, filename_length) && !strstr(filename, "://")) {
478-
char *arch;
479-
size_t arch_len;
480478
zend_string *fname;
481479
zend_stat_t sb = {0};
482480
phar_archive_data *phar;
@@ -490,16 +488,17 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
490488
}
491489

492490
if (PHAR_G(last_phar) && ZSTR_LEN(fname) - 7 >= PHAR_G(last_phar_name_len) && !memcmp(ZSTR_VAL(fname) + 7, PHAR_G(last_phar_name), PHAR_G(last_phar_name_len))) {
493-
arch = estrndup(PHAR_G(last_phar_name), PHAR_G(last_phar_name_len));
494-
arch_len = PHAR_G(last_phar_name_len);
495491
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
496492
phar = PHAR_G(last_phar);
497493
goto splitted;
498494
}
495+
char *arch;
496+
size_t arch_len;
499497
if (SUCCESS == phar_split_fname(ZSTR_VAL(fname), ZSTR_LEN(fname), &arch, &arch_len, NULL, 2, 0)) {
500498
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
501-
if (FAILURE == phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL)) {
502-
efree(arch);
499+
zend_result has_archive = phar_get_archive(&phar, arch, arch_len, NULL, 0, NULL);
500+
efree(arch);
501+
if (FAILURE == has_archive) {
503502
goto skip_phar;
504503
}
505504
splitted:;
@@ -520,7 +519,6 @@ splitted:;
520519
}
521520
if (zend_hash_exists(&(phar->virtual_dirs), entry)) {
522521
zend_string_release_ex(entry, false);
523-
efree(arch);
524522
if (IS_EXISTS_CHECK(type)) {
525523
RETURN_TRUE;
526524
}
@@ -550,7 +548,6 @@ splitted:;
550548
PHAR_G(cwd_len) = save_len;
551549
zend_string_release_ex(entry, false);
552550
if (IS_EXISTS_CHECK(type)) {
553-
efree(arch);
554551
RETURN_TRUE;
555552
}
556553
goto stat_entry;
@@ -559,7 +556,6 @@ splitted:;
559556
PHAR_G(cwd) = save;
560557
PHAR_G(cwd_len) = save_len;
561558
zend_string_release_ex(entry, false);
562-
efree(arch);
563559
if (IS_EXISTS_CHECK(type)) {
564560
RETURN_TRUE;
565561
}
@@ -574,15 +570,13 @@ splitted:;
574570
PHAR_G(cwd) = save;
575571
PHAR_G(cwd_len) = save_len;
576572
zend_string_release_ex(entry, false);
577-
efree(arch);
578573
/* Error Occurred */
579574
if (!IS_EXISTS_CHECK(type)) {
580575
php_error_docref(NULL, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename);
581576
}
582577
RETURN_FALSE;
583578
}
584579
stat_entry:
585-
efree(arch);
586580
if (!data->is_dir) {
587581
sb.st_size = data->uncompressed_filesize;
588582
sb.st_mode = data->flags & PHAR_ENT_PERM_MASK;

0 commit comments

Comments
 (0)