[ee122] Segfault Madness (need expert)

Ofer Sadgat ofer at berkeley.edu
Wed Oct 31 04:23:46 PDT 2007


This is a bug that happened to me a while back. The reason that the bug is
so hard to find is because it errors out on code that did not cause it. I'm
being a bit vague. To be more specific, what happened to me was that an
earlier instruction "segfaulted" BUT there was no error thrown until the
random insertion of some line. When I say segfaulted earlier that could be
one of numerous things. 1. You went out of bounds on memory that was given
to you. 2. You tried to write to some ptr whose value got screwed up and now
you're writing to some potentially deadly place in memory. 3. You try and
free a ptr that has been offset (I think that the last one does this, but Im
not sure).

 

Hope this help.at least a bit.

-Ofer

 

From: ee122-bounces at ICSI.Berkeley.EDU
[mailto:ee122-bounces at ICSI.Berkeley.EDU] On Behalf Of Drew Lustro
Sent: Wednesday, October 31, 2007 2:22 AM
To: ee122 at ICSI.Berkeley.EDU
Subject: [ee122] Segfault Madness (need expert)

 

This may be one of the most difficult to explain problems, but I'll try.
I've been working on the server and everything was OK and then I started
getting segfaults. I was confused since the recent changes did NOT involve
any malloc'ing / freeing of any sort! After some tedious, tedious commenting
and uncommenting (because Eclipse's debugger was totally useless), I found
that if I uncomment a single declaration, the segfaults vanish.

 

I added this BOOL declaration line to the top of processClientInput(client):

 

int processClientInput(sockAndBufs &client)

{

       int bytes = consumeRequestLine(client);

       char ** uri;

       char * uri_string;

                           bool keepAlive = false; // THIS, OF ALL THINGS IS
WHAT CAUSES THE SEGFAULTING

 

       // ... tons more code

       // note: uri and uri_string do involve mallocing, but did not give me
any trouble in the past

 

 

Can any C/C++ Guru shed some light on this? Why would commenting out the
"bool" line lead to no segfaulting? Such an obscure problem is throwing me
off so hard that I'm starting to believe this project is just a
get-pissed-off-at-c project rather than us learning anything new about
socket programming.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/ee122/attachments/20071031/e5f6d8be/attachment-0001.html 


More information about the ee122 mailing list