PHP 4.0 Bug #4734: return $var causes seg fault
| From: | john at vbulletin dot com | Date: | Wed, 31 May 2000 17:22:40 +0000 |
| Subject: | PHP 4.0 Bug #4734: return $var causes seg fault | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-19907@lists.php.net to get a copy of this message | ||
From: john@vbulletin.com
Operating system: Linux
PHP version: 4.0.0 Release
PHP Bug Type: Reproduceable crash
Bug description: return $var causes seg fault
PHP Info output:
PHP Version 4.0.0
System Linux area51.site5.com 2.2.14-5.0smp #1 SMP Tue Mar 7 21:01:40 EST 2000 i686 unknown
Build Date May 22 2000
Configure Command './configure' '--with-apxs=/usr/local/apache/bin/apxs'
'--with-xml' '--with-mysql' '--enable-track-vars'
Server API Apache
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/lib
ZEND_DEBUG enabled
Thread Safety disabled
This program makes use of the Zend scripting language engine:
Zend Engine v1.00, Copyright (c) 1998-2000 Zend Technologies
(The same was happening with PHP4 RC2)
A certain script on this site51 host is causing seg faults. I have narrowed it down to the
str_replace function I think.
Here is the result of the Apache error log:
FATAL: emalloc(): Unable to allocate 1515870815 bytes
[Sun May 21 19:18:38 2000] [notice] child pid 16531 exit signal Segmentation
fault (11)
This is one of the various calls that creates the error:
if ($allowsmilie==1 and $dosmilies==1) {
$smilies=$DB_site->query("SELECT smilietext,smiliepath FROM smilie");
while ($smilie=$DB_site->fetch_array($smilies)) {
if ($smilie[smilietext]!="") {
$bbcode=str_replace($smilie[smilietext],"<img
src=\"$smilie[smiliepath]\">",$bbcode);
}
}
}
Commenting out the str_replace line removes the problem. This call is part of a larger script ( http://www.vbulletin.com/ ), which works fine on every
other server that it has been tested on. Indeed, this script works fine on other site51 sites too.
It seems to be dependent on which database is being used. Lets say that there are 2 sites, A and B,
and 2 MySQL databases C and
D.
Database D works with the PHP code from either site A or site B. Database C however, does not work
from site A (untested on site B). It seems strange, since both databases were installed from the
same script.
[Update!!]
Well I gave up on the backtrace in the end - the site5 support guy just ignored me.
I spent some more time on the problem and narrowed it down to the return statement in the end. The
original code was like this:
function bbcodeparse ($bbcode) {
// do some stuff with $bbcode including many str_replace and eregi_replace
return $bbcode;
}
It was the return that seemed to be causing the crash, so I did this as a
workaround:
function bbcodeparse ($bbcode) {
bbcodeparse2($bbcode;
return $bbcode2;
}
function bbcodeparse2 ($bbcode) {
global $bbcode2;
// do stuff on $bbcode
$bbcode2=$bbcode;
}
And that fixed the problem! I have no idea what caused it, but I got it working. :)
I can provide a copy of the scripts for anyone on the PHP team wanting to look to diagnose the
problem. Just email me:
john@vbulletin.com
Thanks!