php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31446 Memory leak in mysql extension
Submitted: 2005-01-07 23:05 UTC Modified: 2005-01-08 09:25 UTC
From: hexer at studentcenter dot org Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.10 OS: Linux 2.4
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: hexer at studentcenter dot org
New email:
PHP Version: OS:

 

 [2005-01-07 23:05 UTC] hexer at studentcenter dot org
Description:
------------
There is a memory leak when any script that uses
mysql_connect is run.

The call to init_available_charsets() (libmysql/charset.c:177) 
allocates some memory but the call to free_charsets()
is never made at the end of the script execution.

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

// replace params with your mysql host username and password
$db=mysql_connect("127.0.0.1","username","password");

mysql_close($db);
?>

Actual result:
--------------
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes php test.php

Valgrind output:

==20923== 64 bytes in 1 blocks are still reachable in loss record 1 of 1
==20923==    at 0x1B900D20: malloc (vg_replace_malloc.c:131)
==20923==    by 0x8091E71: my_malloc (/usr/local/src/php-4.3.10/ext/mysql/libmysql/my_malloc.c:22)
==20923==    by 0x809708A: init_dynamic_array (/usr/local/src/php-4.3.10/ext/mysql/libmysql/array.c:35)
==20923==    by 0x809949B: init_available_charsets (/usr/local/src/php-4.3.10/ext/mysql/libmysql/charset.c:177)



Further notes:

The call to my_end() (libmysql/my_init.c) contains a call to free_charsets() but my_end() is never called from anywhere.



Php was compiled with:

./configure --with-mysql \
--with-xml \
--with-apache=../apache_1.3.33 \
--enable-track-vars \
--with-gd \
--enable-discard-path \
--enable-bcmath \
--enable-gd-native-tt \
--with-freetype-dir=/usr/local \
--with-png-dir=/usr/local \
--with-jpeg-dir=/usr/local \
--with-zlib=/usr/local


------

-Hexer

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-08 09:25 UTC] georg@php.net
This is a bug in libmysql, not in PHP. 
 
Please check http://bugs.mysql.com/bug.php?id=7619 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 07:01:33 2025 UTC