ID: 49125 Updated by: j...@php.net Reported By: jdornan at stanford dot edu -Status: Open +Status: Closed Bug Type: DBM/DBA related Operating System: * PHP Version: 5.2.10 New Comment:
This bug has been fixed in SVN. 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. Previous Comments: ------------------------------------------------------------------------ [2009-08-01 23:10:11] s...@php.net Automatic comment from SVN on behalf of felipe Revision: http://svn.php.net/viewvc/?view=revision&revision=286636 Log: - Fixed bug #49125 (Error in dba_exists C code) patch by: jdornan at stanford dot edu ------------------------------------------------------------------------ [2009-07-31 20:56:43] jdornan at stanford dot edu Description: ------------ Using dba_exists with a file opened with dba_popen and the db4 handler will result in an error. Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT data I found a similar problem was reported before for dba_fetch. Since dba_fetch and dba_exists share common code it was clear to see how this error could be fixed. Here is a simple diff between the original file and the fixed version. *** dba_db4.c 2009-07-31 13:24:14.000000000 -0400 --- dba_db4.c.fixed 2009-07-31 13:27:49.000000000 -0400 *************** *** 175,181 **** --- 175,187 ---- DB4_GKEY; memset(&gval, 0, sizeof(gval)); + if (info->flags & DBA_PERSISTENT) { + gval.flags |= DB_DBT_MALLOC; + } if (!dba->dbp->get(dba->dbp, NULL, &gkey, &gval, 0)) { + if (info->flags & DBA_PERSISTENT) { + free(gval.data); + } return SUCCESS; } return FAILURE; I checked an the error still exists in the 5.2 snapshot. Reproduce code: --------------- Test #1 <?PHP $db = dba_popen('test.db4', 'c', 'db4'); dba_insert('b0rk', 'b0rk', $db); if (dba_exists('b0rk', $db) == true) { echo 'Yes, we have b0rk!' . PHP_EOL; } ?> Test #2 <?PHP error_reporting(E_ALL); $db = dba_popen('test.db4', 'c', 'db4'); dba_insert('b0rk', 'b0rk', $db); if (dba_exists('b0rk', $db) == true) { echo 'Yes, we have b0rk!' . PHP_EOL; } ?> Expected result: ---------------- Yes, we have b0rk! Actual result: -------------- Test #1 Nothing. Test #2 Notice: dba_exists(): DB_THREAD mandates memory allocation flag on DBT data in /tmp/test2.php on line 8 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49125&edit=1