php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58388 geoip_org_by_name has a memory leak
Submitted: 2008-10-22 10:35 UTC Modified: 2008-11-15 17:02 UTC
From: ktamas77 at gmail dot com Assigned: ohill (profile)
Status: Closed Package: geoip (PECL)
PHP Version: 5.2.5 OS: CentOS
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: ktamas77 at gmail dot com
New email:
PHP Version: OS:

 

 [2008-10-22 10:35 UTC] ktamas77 at gmail dot com
Description:
------------
geoip_org_by_name() function has a memory leak.
It doesn't clear for me, is it because of the PECL module, 
or the bug is in the underlying MaxMind library (v1.4.4) but  
the attached oneliner script will eat up all the memory.





Reproduce code:
---------------
<?php

$ip = "195.70.35.7";
while (true) $geo_org = geoip_org_by_name ($ip);

?>



Expected result:
----------------
It shouldn't eat up all the free memory.

Actual result:
--------------
It allocates more and more memory until it run out.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-22 17:08 UTC] Boris Zentner<bzm at 2bz dot de>
Hi,

here is a patch to fix some memory leaks.

diff -Nur a/geoip.c b/geoip.c
--- a/geoip.c	2008-10-22 22:33:02.000000000 +0200
+++ b/geoip.c	2008-10-22 22:39:07.000000000 +0200
@@ -359,7 +359,8 @@
 		php_error_docref(NULL TSRMLS_CC, E_NOTICE, 
"Host %s not found", hostname);
 		RETURN_FALSE;
 	}
-	RETURN_STRING((char*)country_name, 1);
+	RETVAL_STRING(country_name, 1);
+	free(country_name);
 }
 /* }}} */
 
@@ -419,7 +420,9 @@
 		php_error_docref(NULL TSRMLS_CC, E_NOTICE, 
"Host %s not found", hostname);
 		RETURN_FALSE;
 	}
-	RETURN_STRING((char*)org, 1);
+
+	RETVAL_STRING(org, 1);
+	free(org);
 }
 /* }}} */
 
@@ -563,7 +566,8 @@
 		php_error_docref(NULL TSRMLS_CC, E_NOTICE, 
"Host %s not found", hostname);
 		RETURN_FALSE;
 	}
-	RETURN_STRING((char*)isp, 1);
+	RETVAL_STRING(isp, 1);
+	free(isp);
 }
 [2008-10-22 17:51 UTC] ohill@php.net
Thanks. Not home right now, but will apply in the next days.
 [2008-11-15 17:02 UTC] ohill@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 05:01:27 2024 UTC