php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77998 Memory leak in phpdbg_start_oplog
Submitted: 2019-05-10 06:58 UTC Modified: 2019-05-10 07:25 UTC
From: andrew at nicols dot co dot uk Assigned:
Status: Not a bug Package: phpdbg
PHP Version: 7.3.5 OS: MacOS. Also Offical docker image
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew at nicols dot co dot uk
New email:
PHP Version: OS:

 

 [2019-05-10 06:58 UTC] andrew at nicols dot co dot uk
Description:
------------
Once phpdbg_start_oplog() has been called memory usage increases as data is generated, whether or not it is assigned to a variable and garbage collection does not improve this.

The below test script demonstrates how the memory usage can grow in a short space of time. The memory increases just from the increment of $i, even if you remove the str_repeat.

On a large project, this causes the memory usage to grow as phpunit is run when generating coverage reports, until hitting the memory limit.


Test script:
---------------
<?php

function get_something($repeats) {
    for ($i = 0; $i < $repeats; $i++) {
        // Generate a 1MB string.
        str_repeat(rand(1, 10), 1 * 1024 * 1024);
    }
}

function print_memory_usage() {
    static $memory = null;
    if (null === $memory) {
        $memory = memory_get_usage();
    }
    printf("Memory is at %d bytes\n", memory_get_usage() - $memory);
}

function run($repeats) {
    print_memory_usage();
    for ($i = 0; $i < $repeats; $i++) {
        get_something($repeats);
        print_memory_usage();
    }

    print_memory_usage();
    gc_collect_cycles();
    print_memory_usage();
}

$repeats = 50;

echo "Running without phpdbg_start_oplog:\n";
run($repeats);

echo "Running with phpdbg_start_oplog:\n";
\phpdbg_start_oplog();
run($repeats);

Expected result:
----------------
2005 sm:master> phpdbg -qrr test.php
Running without phpdbg_start_oplog:
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Running with phpdbg_start_oplog:
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes

Actual result:
--------------
2005 sm:master> phpdbg -qrr test.php
Running without phpdbg_start_oplog:
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Memory is at 0 bytes
Running with phpdbg_start_oplog:
Memory is at 65552 bytes
Memory is at 65552 bytes
Memory is at 65552 bytes
Memory is at 131088 bytes
Memory is at 131088 bytes
Memory is at 196624 bytes
Memory is at 196624 bytes
Memory is at 196624 bytes
Memory is at 262160 bytes
Memory is at 262160 bytes
Memory is at 327696 bytes
Memory is at 327696 bytes
Memory is at 393232 bytes
Memory is at 393232 bytes
Memory is at 393232 bytes
Memory is at 458768 bytes
Memory is at 458768 bytes
Memory is at 524304 bytes
Memory is at 524304 bytes
Memory is at 524304 bytes
Memory is at 589840 bytes
Memory is at 589840 bytes
Memory is at 655376 bytes
Memory is at 655376 bytes
Memory is at 720912 bytes
Memory is at 720912 bytes
Memory is at 720912 bytes
Memory is at 786448 bytes
Memory is at 786448 bytes
Memory is at 851984 bytes
Memory is at 851984 bytes
Memory is at 917520 bytes
Memory is at 917520 bytes
Memory is at 917520 bytes
Memory is at 983056 bytes
Memory is at 983056 bytes
Memory is at 1048592 bytes
Memory is at 1048592 bytes
Memory is at 1048592 bytes
Memory is at 1114128 bytes
Memory is at 1114128 bytes
Memory is at 1179664 bytes
Memory is at 1179664 bytes
Memory is at 1245200 bytes
Memory is at 1245200 bytes
Memory is at 1245200 bytes
Memory is at 1310736 bytes
Memory is at 1310736 bytes
Memory is at 1376272 bytes
Memory is at 1376272 bytes
Memory is at 1376272 bytes
Memory is at 1376272 bytes
Memory is at 1376272 bytes

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-10 07:03 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2019-05-10 07:03 UTC] krakjoe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2019-05-10 07:25 UTC] andrew at nicols dot co dot uk
Can you please explain how this is not a bug?

There is no documentatino for phpdbg_start_oplog(), so if it is an expected feature, it is not a documented one.
https://www.php.net/manual/en/function.phpdbg-start-oplog.php

I believe that I have followed the documentation on how to raise a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC