Segmentation Fault calling Method

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jcobban
Forum Commoner
Posts: 41
Joined: Mon Mar 08, 2010 7:40 am

Segmentation Fault calling Method

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Segmentation Fault calling Method

Post 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?
jcobban
Forum Commoner
Posts: 41
Joined: Mon Mar 08, 2010 7:40 am

Re: Segmentation Fault calling Method

Post 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.
jcobban
Forum Commoner
Posts: 41
Joined: Mon Mar 08, 2010 7:40 am

Re: Segmentation Fault calling Method

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Segmentation Fault calling Method

Post 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.
Post Reply