]> granicus.if.org Git - php/commitdiff
Fixed resource leak
authorDmitry Stogov <dmitry@zend.com>
Thu, 31 Jul 2014 06:53:31 +0000 (10:53 +0400)
committerDmitry Stogov <dmitry@zend.com>
Thu, 31 Jul 2014 06:53:31 +0000 (10:53 +0400)
main/php_streams.h
main/streams/streams.c

index 2a142b99c2a8ddbb631e20624826e7f5b2b1714f..fac15ce3e4a58f9a5dc4c036187f6525feb8539c 100644 (file)
@@ -202,9 +202,7 @@ struct _php_stream  {
         * PHP_STREAM_FCLOSE_XXX as appropriate */
        int fclose_stdiocast;
        FILE *stdiocast;    /* cache this, otherwise we might leak! */
-#if ZEND_DEBUG
        int __exposed;  /* non-zero if exposed as a zval somewhere */
-#endif
        char *orig_path;
 
        php_stream_context *context;
@@ -243,17 +241,12 @@ END_EXTERN_C()
 #define php_stream_alloc(ops, thisptr, persistent_id, mode)    _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC)
 
 #define php_stream_get_resource_id(stream)             ((php_stream *)(stream))->res->handle
-#if ZEND_DEBUG
 /* use this to tell the stream that it is OK if we don't explicitly close it */
-# define php_stream_auto_cleanup(stream)       { (stream)->__exposed++; }
+#define php_stream_auto_cleanup(stream)        { (stream)->__exposed++; }
 /* use this to assign the stream to a zval and tell the stream that is
  * has been exported to the engine; it will expect to be closed automatically
  * when the resources are auto-destructed */
-# define php_stream_to_zval(stream, zval)      { ZVAL_RES(zval, (stream)->res); (stream)->__exposed++; }
-#else
-# define php_stream_auto_cleanup(stream)       /* nothing */
-# define php_stream_to_zval(stream, zval)      { ZVAL_RES(zval, (stream)->res); }
-#endif
+#define php_stream_to_zval(stream, zval)       { ZVAL_RES(zval, (stream)->res); (stream)->__exposed++; }
 
 #define php_stream_from_zval(xstr, pzval)      ZEND_FETCH_RESOURCE2((xstr), php_stream *, (pzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
 #define php_stream_from_zval_no_verify(xstr, pzval)    (xstr) = (php_stream*)zend_fetch_resource((pzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
index f305fe8044bc0c92de8b72948ac57fc1c1c6e0bb..648a0d8c6d8b61ccd557406aba9aeae14c2c3a76 100644 (file)
@@ -466,6 +466,10 @@ fprintf(stderr, "stream_free: %s:%p[%s] preserve_handle=%d release_cast=%d remov
 //???          while (zend_list_delete(stream->res) == SUCCESS) {}
 //???          stream->res->gc.refcount = 0;
                zend_list_close(stream->res);
+               if (!stream->__exposed) {
+                       zend_list_delete(stream->res);
+                       stream->res = NULL;
+               }
        }
 
        if (close_options & PHP_STREAM_FREE_CALL_DTOR) {