Page 1 of 1

Segmentation Fault calling Method

Posted: Tue Sep 30, 2014 9:31 pm
by jcobban
I am getting a segmentation fault when I call a method of an object. The method is actually implemented in the base class, and I call the same method in a lot of different places in my site, but when I call it in this particular case I get a segmentation fault.

Code: Select all

	print "<p>\$picture=" . print_r($picture, true) . "</p>\n";
	// apply any changes passed in parameters
	if (method_exists($picture, 'postUpdate'))
	    print "<p>object has a postUpdate method</p>\n";
	else
	    print "<p>object does not have a postUpdate method</p>\n";
	$picture->postUpdate(true);
If I place an exit command immediately prior to calling postUpdate I see:

Code: Select all

    $picture=LegacyPicture Object ( [row:protected] => Array ( [idbr] => 0 [idir] => 20553 [idtype] => 0 [pictype] => 0 [picorder] => 0 [picname] => [picnameurl] => [idbppic] => 1 [piccaption] => [picd] => [picsd] => [picdate] => [picdesc] => [picprint] => 0 [picsoundname] => [picsoundnameurl] => [idbpsound] => 0 [used] => 0 [picpref] => 1 [filingref] => ) [changed:protected] => Array ( ) [table:Record:private] => tblBR [prime:Record:private] => idbr [needInsert:protected] => 1 )

    object has a postUpdate method.
If I place an exit command in the very first line of the method postUpdate PHP gets a segmentation fault. The method postUpdate just updates the contents of the object based upon $_POST. There is no recursion. The fault happens immediately. What could go wrong in between calling the method and the very first line of code in the method that would cause a segmentation fault? Running PHP Version 5.5.9 on Apache 2.4.7.

Re: Segmentation Fault calling Method

Posted: Wed Oct 01, 2014 1:30 am
by requinix
Can you set up a debugger to trace execution? Maybe there's something else happening in between.

And is it an actual segfault? Or just a crash?

Re: Segmentation Fault calling Method

Posted: Wed Oct 01, 2014 11:33 am
by jcobban
Thank you.

To run the debugger I would have to recompile PHP with the debugging option and then run the entire Apache server under the debugger. That does not strike me as practical.

From error.log:

[Tue Sep 30 22:06:00.392895 2014] [core:notice] [pid 9440] AH00051: child pid 9863 exit signal Segmentation fault (11), possible coredump in /etc/apache2

I could use gdb to analyze the core dump, but that would again require me to recompile PHP with the debugging option.

Re: Segmentation Fault calling Method

Posted: Wed Oct 01, 2014 12:03 pm
by jcobban
I kept digging, looking through the code of the methods called by the method postUpdate and found an error that caused an infinite recursion. So this is the same old recursion fault. Thanks for the help.

Re: Segmentation Fault calling Method

Posted: Wed Oct 01, 2014 3:03 pm
by requinix
I didn't mean a full GDB debugger - just the XDebug extension. A bit of work to set it up but nothing like a full compile.

So yeah, actual segfaults are generally caused by infinite recursion, however exit;ing at the very beginning of that method should have stopped it from happening... But whatever, glad that it's solved.