Skip to content

Memory leak in ArrayIterator when manually calling __construct() #8366

Closed

Description

@TimWolla

Description

When running the following code:

<?php

$it = new \ArrayIterator();
$it->next();
$it->__construct([]);

PHP will report a memory leak ("Warning: Leaked 1 hashtable iterators in Unknown on line 0"):

==271560== Memcheck, a memory error detector
==271560== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==271560== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==271560== Command: sapi/cli/php test.php
==271560== 

Warning: Leaked 1 hashtable iterators in Unknown on line 0
==271560== 
==271560== HEAP SUMMARY:
==271560==     in use at exit: 0 bytes in 0 blocks
==271560==   total heap usage: 14,371 allocs, 14,371 frees, 2,141,349 bytes allocated
==271560== 
==271560== All heap blocks were freed -- no leaks are possible
==271560== 
==271560== For lists of detected and suppressed errors, rerun with: -s
==271560== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

PHP Version

PHP 8.2.0-dev (commit 8233e06)

Operating System

Ubuntu 20.04

Activity

  1. morrisonlevi commented on Apr 13, 2022

    @morrisonlevi
    Contributor

    Ugh, IMO we need to emit warnings or exceptions when rewind() has been skipped for most built-in iterators -- this would prevent at least part of this bug from happening.

  2. added a commit that references this issue on Apr 14, 2022
    92dc0be
  3. added 2 commits that reference this issue on Apr 15, 2022
    1762a87
    549cf3a
  4. added a commit that references this issue on Apr 15, 2022
    3de0ccf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions