php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9377 memory leaks on error in array_push() and array_unshift()
Submitted: 2001-02-21 12:20 UTC Modified: 2001-02-21 12:24 UTC
From: chris at nameboy dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.4pl1 OS: Redhat Linux 6.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chris at nameboy dot com
New email:
PHP Version: OS:

 

 [2001-02-21 12:20 UTC] chris at nameboy dot com
Both array_push() and array_unshift() leak memory when
called with a non-array first parameter (which generates an
error, of course)

For example:
<?
$abc = 0;
for($i=0; $i<5000000; $i++) {
  @array_push($abc, 123);
}
?>

Patch follows...

--- php-4.0.4pl1/ext/standard/array.c.ORIG      Wed Feb 21
09:07:13 2001
+++ php-4.0.4pl1/ext/standard/array.c   Wed Feb 21 08:59:59 2001
@@ -1501,6 +1501,7 @@
        stack = *args[0];
        if (Z_TYPE_P(stack) != IS_ARRAY) {
                php_error(E_WARNING, "First argument to
array_push() needs to be an array");
+               efree(args);
                RETURN_FALSE;
        }
 
@@ -1605,6 +1606,7 @@
        stack = *args[0];
        if (Z_TYPE_P(stack) != IS_ARRAY) {
                php_error(E_WARNING, "First argument to
array_unshift() needs to be an array");
+               efree(args);
                RETURN_FALSE;
        }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-21 12:24 UTC] andrei@php.net
Applied, thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC