php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43371 Memory errors in PDO constructor
Submitted: 2007-11-22 09:24 UTC Modified: 2008-09-22 01:00 UTC
From: poletto at jeuxvideo dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.5 OS: Linux 2.4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-11-22 09:24 UTC] poletto at jeuxvideo dot com
Description:
------------
There were some crashes with 5.2.4 when using pdo, so i've tried out 5.2.5 that seems to have fixed this crashes.
Just to make sure there was no problem, i've tried to valgrind the command line program on a simple script using pdo.
There are a few memory errors (this can make crashes occur).
Note that the leaks are due to the kernel 2.4 threads (so, ignore them).


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

$dbh = new PDO('mysql:host=host;dbname=db', 'user', 'pass', array(PDO::ATTR_PERSISTENT => true));

?>


Expected result:
----------------
No memory errors

Actual result:
--------------
Valgrind's output

> valgrind -q --leak-check=full --show-reachable=yes /usr/local/src/php-5.2.5/sapi/cli/php test_pdo.php
==10313== Invalid read of size 4
==10313==    at 0x40B29BD: my_strdup (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x40D61D5: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x80F384C: pdo_mysql_handle_factory (mysql_driver.c:553)
==10313==    by 0x80EAC76: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==  Address 0x471F388 is 8 bytes inside a block of size 9 alloc'd
==10313==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==10313==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x80EAB51: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==
==10313== Invalid read of size 4
==10313==    at 0x40B1BC2: scramble (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x40D654D: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x80F384C: pdo_mysql_handle_factory (mysql_driver.c:553)
==10313==    by 0x80EAC76: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==  Address 0x471F388 is 8 bytes inside a block of size 9 alloc'd
==10313==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==10313==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x80EAB51: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==
==10313== Invalid read of size 4
==10313==    at 0x40B15E1: scramble_323 (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x40D66F3: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==10313==    by 0x80F384C: pdo_mysql_handle_factory (mysql_driver.c:553)
==10313==    by 0x80EAC76: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==  Address 0x471F388 is 8 bytes inside a block of size 9 alloc'd
==10313==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==10313==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x80EAB51: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==10313==    by 0x8237479: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200)
==10313==    by 0x8236D44: execute (zend_vm_execute.h:92)
==10313==    by 0x8220018: zend_execute_scripts (zend.c:1134)
==10313==    by 0x81ED74F: php_execute_script (main.c:2004)
==10313==    by 0x827A9B1: main (php_cli.c:1140)
==10313==
==10313==
==10313== 28 bytes in 1 blocks are still reachable in loss record 1 of 4
==10313==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==10313==    by 0x400B875: _dl_map_object_deps (in /lib/ld-2.3.2.so)
==10313==    by 0x4532DBA: dl_open_worker (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x400C895: _dl_catch_error (in /lib/ld-2.3.2.so)
==10313==    by 0x45329AE: _dl_open (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x45347C7: do_dlopen (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x400C895: _dl_catch_error (in /lib/ld-2.3.2.so)
==10313==    by 0x453468D: __libc_dlopen_mode (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x4512C30: __nss_lookup_function (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x451287A: __nss_lookup (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x4514616: __nss_services_lookup (in /lib/i686/libc-2.3.2.so)
==10313==    by 0x4517C61: getservbyname_r@@GLIBC_2.1.2 (in /lib/i686/libc-2.3.2.so)
==10313==
==10313==
==10313== 68 bytes in 1 blocks are possibly lost in loss record 2 of 4
==10313==    at 0x401BC54: calloc (vg_replace_malloc.c:279)
==10313==    by 0x400EBE8: _dl_allocate_tls_storage (in /lib/ld-2.3.2.so)
==10313==    by 0x400EDD8: _dl_allocate_tls (in /lib/ld-2.3.2.so)
==10313==    by 0x43D756B: __pthread_initialize_minimal (in /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D4205: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D3C52: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x400CC51: _dl_init (in /lib/ld-2.3.2.so)
==10313==    by 0x4000C5C: (within /lib/ld-2.3.2.so)
==10313==
==10313==
==10313== 520 bytes in 1 blocks are still reachable in loss record 3 of 4
==10313==    at 0x401BC54: calloc (vg_replace_malloc.c:279)
==10313==    by 0x400EAF7: _dl_tls_setup (in /lib/ld-2.3.2.so)
==10313==    by 0x43D755C: __pthread_initialize_minimal (in /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D4205: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D3C52: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x400CC51: _dl_init (in /lib/ld-2.3.2.so)
==10313==    by 0x4000C5C: (within /lib/ld-2.3.2.so)
==10313==
==10313==
==10313== 1,288 bytes in 1 blocks are possibly lost in loss record 4 of 4
==10313==    at 0x401BE0C: memalign (vg_replace_malloc.c:332)
==10313==    by 0x400EBA1: _dl_allocate_tls_storage (in /lib/ld-2.3.2.so)
==10313==    by 0x400EDD8: _dl_allocate_tls (in /lib/ld-2.3.2.so)
==10313==    by 0x43D756B: __pthread_initialize_minimal (in /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D4205: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x43D3C52: (within /lib/i686/libpthread-0.10.so)
==10313==    by 0x400CC51: _dl_init (in /lib/ld-2.3.2.so)
==10313==    by 0x4000C5C: (within /lib/ld-2.3.2.so)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-22 14:57 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.3-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.3-win32-installer-latest.msi

I've tried to replicate the problem, but for me valgrind reports no 
errors.
 [2007-11-22 15:20 UTC] poletto at jeuxvideo dot com
Same problem... Maybe a problem inside libmysqlclient?

> valgrind -q /usr/local/src/php5.3-200711221330/sapi/cli/php test_pdo.php
==6951== Invalid read of size 4
==6951==    at 0x40B29BD: my_strdup (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x40D61D5: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x80F97AC: pdo_mysql_handle_factory (mysql_driver.c:553)
==6951==    by 0x80F0BE2: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
==6951==  Address 0x470E900 is 8 bytes inside a block of size 9 alloc'd
==6951==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==6951==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==6951==    by 0x80F0ABD: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
==6951==
==6951== Invalid read of size 4
==6951==    at 0x40B1BC2: scramble (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x40D654D: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x80F97AC: pdo_mysql_handle_factory (mysql_driver.c:553)
==6951==    by 0x80F0BE2: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
==6951==  Address 0x470E900 is 8 bytes inside a block of size 9 alloc'd
==6951==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==6951==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==6951==    by 0x80F0ABD: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
==6951==
==6951== Invalid read of size 4
==6951==    at 0x40B15E1: scramble_323 (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x40D66F3: mysql_real_connect (in /usr/local/MySQL-5.0.45/lib/libmysqlclient.so.15)
==6951==    by 0x80F97AC: pdo_mysql_handle_factory (mysql_driver.c:553)
==6951==    by 0x80F0BE2: zim_PDO_dbh_constructor (pdo_dbh.c:372)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
==6951==  Address 0x470E900 is 8 bytes inside a block of size 9 alloc'd
==6951==    at 0x401A826: malloc (vg_replace_malloc.c:149)
==6951==    by 0x449A33F: strdup (in /lib/i686/libc-2.3.2.so)
==6951==    by 0x80F0ABD: zim_PDO_dbh_constructor (pdo_dbh.c:358)
==6951==    by 0x82380AA: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:191)
==6951==    by 0x823790C: execute (zend_vm_execute.h:87)
==6951==    by 0x822019C: zend_execute_scripts (zend.c:1139)
==6951==    by 0x81E959B: php_execute_script (main.c:2008)
==6951==    by 0x8280E39: main (php_cli.c:1140)
 [2007-11-22 16:40 UTC] iliaa@php.net
It could be libmysqlclient related as you had suggested, can you try a 
different version perhaps?
 [2007-11-22 17:09 UTC] poletto at jeuxvideo dot com
I can't try another version of mysql on this server.
I noticed there was no error when removing the persistant connection
 [2008-07-03 17:02 UTC] uw@php.net
Can't reproduce with 5.3 CVS, PDO_MYSQLND and MySQL 5.0.51b-debug Source distribution. No matter if I use mysqlnd or libmysql.

I haven't check PDO_MYSQL any more.

However, PDOs management of persistent connections seems to be not perfect. I know of such an error:

done![Thu Jul  3 18:59:39 2008]  Script:  'ext/pdo_mysqlnd/tests/pdo_mysql_pconnect.php'
/home/nixnutz/php53/ext/pdo/pdo_dbh.c(1514) :  Freeing 0x06601898 (64 bytes), script=ext/pdo_mysqlnd/tests/pdo_mysql_pconnect.php
/home/nixnutz/php53/Zend/zend_alloc.c(2374) : Actual location (location was relayed)
Last leak repeated 21 times
[Thu Jul  3 18:59:39 2008]  Script:  'ext/pdo_mysqlnd/tests/pdo_mysql_pconnect.php'
/home/nixnutz/php53/ext/pdo/pdo_dbh.c(1513) :  Freeing 0x06602910 (72 bytes), script=ext/pdo_mysqlnd/tests/pdo_mysql_pconnect.php
Last leak repeated 21 times
=== Total 44 memory leaks detected ===
==12737==
==12737== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
 [2008-09-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC