php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27295 Memory Leak with sscanf
Submitted: 2004-02-17 15:14 UTC Modified: 2004-02-18 14:42 UTC
From: jwalker7281 at yahoo dot com Assigned: iliaa (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4CVS, 5CVS OS: Redhat Linux 9
Private report: No CVE-ID: None
 [2004-02-17 15:14 UTC] jwalker7281 at yahoo dot com
Description:
------------
I found that using sscanf, at least within a foreach loop, leaks. The original code I found this in read in a file, and then did foreach( $lines as $line )... I wrote a small bit of code to simulate that. It doesn't give the same files for a leak location, but it still leaks.

When running my code, I got this:
/root/php-5.0.0b4/Zend/zend_execute.c(2973) :  Freeing 0x40232D30 (2 bytes), script=./objtest
/root/php-5.0.0b4/Zend/zend_variables.c(137) : Actual location (location was relayed)
=== Total 1 memory leaks detected ===

When running this test simulation code, I got this:
/root/php-5.0.0b4/ext/standard/scanf.c(937) :  Freeing 0x4022727C (4 bytes), script=./memleak
=== Total 1 memory leaks detected ===

Both are running PHP5, b4 in CLI mode.

Reproduce code:
---------------
#!/usr/local/bin/php -q
<?php
   $strings = array( "#dude = me\n", "#bug = nasty\n" );
   foreach( $strings as $string )
   {
      sscanf( $string, "%s = %[^[]]", $var, $val );
      echo "$var = $val\n";
   }
?>


Expected result:
----------------
It *works*, as in it outputs:

./memleak
#dude = me

#bug = nasty

But it also gives that memory leak bug.

Actual result:
--------------
Please see above.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-18 14:42 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC