@@ -162,7 +162,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
162162{
163163 phar_archive_data * phar ;
164164 phar_entry_data * idata ;
165- char * internal_file ;
165+ const char * internal_file ;
166166 char * error ;
167167 HashTable * pharcontext ;
168168 php_url * resource = NULL ;
@@ -189,7 +189,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
189189 phar_request_initialize ();
190190
191191 /* strip leading "/" */
192- internal_file = estrndup ( ZSTR_VAL (resource -> path ) + 1 , ZSTR_LEN ( resource -> path ) - 1 ) ;
192+ internal_file = ZSTR_VAL (resource -> path ) + 1 ;
193193 if (mode [0 ] == 'w' || (mode [0 ] == 'r' && mode [1 ] == '+' )) {
194194 if (NULL == (idata = phar_get_or_create_entry_data (ZSTR_VAL (resource -> host ), ZSTR_LEN (resource -> host ), internal_file , strlen (internal_file ), mode , 0 , & error , 1 ))) {
195195 if (error ) {
@@ -198,7 +198,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
198198 } else {
199199 php_stream_wrapper_log_error (wrapper , options , "phar error: file \"%s\" could not be created in phar \"%s\"" , internal_file , ZSTR_VAL (resource -> host ));
200200 }
201- efree (internal_file );
202201 php_url_free (resource );
203202 return NULL ;
204203 }
@@ -207,7 +206,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
207206 }
208207 fpf = php_stream_alloc (& phar_ops , idata , NULL , mode );
209208 php_url_free (resource );
210- efree (internal_file );
211209
212210 if (context && Z_TYPE (context -> options ) != IS_UNDEF && (pzoption = zend_hash_str_find (HASH_OF (& context -> options ), "phar" , sizeof ("phar" )- 1 )) != NULL ) {
213211 pharcontext = HASH_OF (pzoption );
@@ -237,15 +235,13 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
237235 /* retrieve the stub */
238236 if (FAILURE == phar_get_archive (& phar , ZSTR_VAL (resource -> host ), ZSTR_LEN (resource -> host ), NULL , 0 , NULL )) {
239237 php_stream_wrapper_log_error (wrapper , options , "file %s is not a valid phar archive" , ZSTR_VAL (resource -> host ));
240- efree (internal_file );
241238 php_url_free (resource );
242239 return NULL ;
243240 }
244241 if (phar -> is_tar || phar -> is_zip ) {
245242 if ((FAILURE == phar_get_entry_data (& idata , ZSTR_VAL (resource -> host ), ZSTR_LEN (resource -> host ), ".phar/stub.php" , sizeof (".phar/stub.php" )- 1 , "r" , 0 , & error , 0 )) || !idata ) {
246243 goto idata_error ;
247244 }
248- efree (internal_file );
249245 if (opened_path ) {
250246 * opened_path = strpprintf (MAXPATHLEN , "%s" , phar -> fname );
251247 }
@@ -256,7 +252,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
256252 if (stream == NULL ) {
257253 if (UNEXPECTED (FAILURE == phar_open_archive_fp (phar ))) {
258254 php_stream_wrapper_log_error (wrapper , options , "phar error: could not reopen phar \"%s\"" , ZSTR_VAL (resource -> host ));
259- efree (internal_file );
260255 php_url_free (resource );
261256 return NULL ;
262257 }
@@ -285,7 +280,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
285280 if (opened_path ) {
286281 * opened_path = strpprintf (MAXPATHLEN , "%s" , phar -> fname );
287282 }
288- efree (internal_file );
289283 goto phar_stub ;
290284 }
291285 }
@@ -298,7 +292,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
298292 } else {
299293 php_stream_wrapper_log_error (wrapper , options , "phar error: \"%s\" is not a file in phar \"%s\"" , internal_file , ZSTR_VAL (resource -> host ));
300294 }
301- efree (internal_file );
302295 php_url_free (resource );
303296 return NULL ;
304297 }
@@ -317,7 +310,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
317310 php_stream_wrapper_log_error (wrapper , options , "%s" , error );
318311 efree (error );
319312 phar_entry_delref (idata );
320- efree (internal_file );
321313 return NULL ;
322314 }
323315
@@ -340,7 +332,6 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
340332 if (opened_path ) {
341333 * opened_path = zend_strpprintf_unchecked (MAXPATHLEN , "phar://%s/%S" , idata -> phar -> fname , idata -> internal_file -> filename );
342334 }
343- efree (internal_file );
344335phar_stub :
345336 fpf = php_stream_alloc (& phar_ops , idata , NULL , mode );
346337 return fpf ;
@@ -662,7 +653,8 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
662653static int phar_wrapper_unlink (php_stream_wrapper * wrapper , const char * url , int options , php_stream_context * context ) /* {{{ */
663654{
664655 php_url * resource ;
665- char * internal_file , * error ;
656+ const char * internal_file ;
657+ char * error ;
666658 int internal_file_len ;
667659 phar_entry_data * idata ;
668660 phar_archive_data * pphar ;
@@ -695,7 +687,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
695687 }
696688
697689 /* need to copy to strip leading "/", will get touched again */
698- internal_file = estrndup ( ZSTR_VAL (resource -> path ) + 1 , ZSTR_LEN ( resource -> path ) - 1 ) ;
690+ internal_file = ZSTR_VAL (resource -> path ) + 1 ;
699691 internal_file_len = ZSTR_LEN (resource -> path ) - 1 ;
700692 if (FAILURE == phar_get_entry_data (& idata , ZSTR_VAL (resource -> host ), ZSTR_LEN (resource -> host ), internal_file , internal_file_len , "r" , 0 , & error , 1 )) {
701693 /* constraints of fp refcount were not met */
@@ -705,7 +697,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
705697 } else {
706698 php_stream_wrapper_log_error (wrapper , options , "unlink of \"%s\" failed, file does not exist" , url );
707699 }
708- efree (internal_file );
709700 php_url_free (resource );
710701 return 0 ;
711702 }
@@ -715,13 +706,11 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
715706 if (idata -> internal_file -> fp_refcount > 1 ) {
716707 /* more than just our fp resource is open for this file */
717708 php_stream_wrapper_log_error (wrapper , options , "phar error: \"%s\" in phar \"%s\", has open file pointers, cannot unlink" , internal_file , ZSTR_VAL (resource -> host ));
718- efree (internal_file );
719709 php_url_free (resource );
720710 phar_entry_delref (idata );
721711 return 0 ;
722712 }
723713 php_url_free (resource );
724- efree (internal_file );
725714 phar_entry_remove (idata , & error );
726715 if (error ) {
727716 php_stream_wrapper_log_error (wrapper , options , "%s" , error );
0 commit comments