iliaa           Mon Jul 28 14:57:28 2003 EDT

  Modified files:              
    /php-src/main/streams       streams.c 
  Log:
  Fixed a double free bug when freeing persistent streams.
  
  
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.30 php-src/main/streams/streams.c:1.31
--- php-src/main/streams/streams.c:1.30 Wed Jul  2 18:18:59 2003
+++ php-src/main/streams/streams.c      Mon Jul 28 14:57:28 2003
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.30 2003/07/02 22:18:59 pollita Exp $ */
+/* $Id: streams.c,v 1.31 2003/07/28 18:57:28 iliaa Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -254,7 +254,7 @@
 
 static int _php_stream_free_persistent(list_entry *le, void *pStream TSRMLS_DC)
 {
-       return le->ptr == pStream;
+       return (le->ptr == pStream && !((php_stream *)pStream)->in_free);
 }
 
 PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC) /* {{{ */
@@ -336,8 +336,6 @@
        }
 
        if (close_options & PHP_STREAM_FREE_RELEASE_STREAM) {
-               int was_persistent = stream->is_persistent;
-               
                while (stream->readfilters.head) {
                        php_stream_filter_remove(stream->readfilters.head, 1 
TSRMLS_CC);
                }
@@ -359,7 +357,11 @@
                        pefree(stream->readbuf, stream->is_persistent);
                        stream->readbuf = NULL;
                }
-               
+
+               if (stream->is_persistent) {
+                       /* we don't work with *stream but need its value for 
comparison */
+                       zend_hash_apply_with_argument(&EG(persistent_list), 
(apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC);
+               }
 #if ZEND_DEBUG
                if ((close_options & PHP_STREAM_FREE_RSRC_DTOR) && (stream->__exposed 
== 0) && (EG(error_reporting) & E_WARNING)) {
                        /* it leaked: Lets deliberately NOT pefree it so that the 
memory manager shows it
@@ -389,10 +391,6 @@
 #else
                pefree(stream, stream->is_persistent);
 #endif
-               if (was_persistent) {
-                       /* we don't work with *stream but need its value for 
comparison */
-                       zend_hash_apply_with_argument(&EG(persistent_list), 
(apply_func_arg_t) _php_stream_free_persistent, stream TSRMLS_CC);
-               }
        }
 
        return ret;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to