Segmentation fault in FreeBSD 9.0 flockfile ()

Robert Bonomi bonomi at
Wed May 2 06:37:41 UTC 2012

Unga <unga888 at> wrote;
> From: Darren Baginski <kickbsd at>
> > Unga <unga888 at> wrote:
> > 
> >01.05.2012, 22:08, "Unga" <unga888 at>:
> >> Hi all
> >>
> >> I'm getting a  Segmentation fault in FreeBSD 9.0 as follows for myprog.c:
> >>
> >> Reading symbols from /libexec/
> >> Loaded symbols for /libexec/
> >> #0  0x28ebb062 in flockfile () from /lib/
> >> [New Thread 29c04900 (LWP 100575/SDLTimer)]
> >> [New Thread 29c04300 (LWP 100416/myprog)]
> >> (gdb)
> >> (gdb) info threads
> >> * 2 Thread 29c04300 (LWP 100416/myprog)  0x28ebb062 in flockfile ()
> >>    from /lib/
> >>   1 Thread 29c04900 (LWP 100575/SDLTimer)  0x28e1527b in _umtx_op ()
> >>    from /lib/
> >> (gdb)
> >>
> >> I don't use flockfile () directly in my program.
> >>
> >
> >Hi!
> >
> >Mind to share code snippet caused the problem?
> Hi Thanks for the reply. I have mentioned in my original post that neithe
> r I nor SDL use the flockfile () in the source.

There was a _reason_ the prior poster asked about seeing your code.
The information you provided is not adequate/sufficient for anyone to
have any chance of helping you.  Informationn that -is- necessary was
therefore requested.  

What you "don't use" is irrelevant to solving the problem. 

To be any help one must figure out what you _did_ do -- which =indirectly= 
calls flockfile().

Your code calls "something" in 'libc'  that calls flockfile().

You "don't know" what that something in your code is.  Other eyes _might_
recognize it, -if- they saw what you were doing.

Here is how to find out what does that calling, yourself.
 1) recompile all the components of 'myprog' with the '-g' compiler option.
 2) start 'script', so that you have a complete log of the debugger session.
 3) load the debugger with 'myprog' as the program to be debugged.
 4) set a breakpoinnt in the 'flockfile' function
 5) 'run' the program
 6) when it stops at flockfile() entry. use 'where' to see a stack trace.
 7) 'display' each of the arguments to flockfile().
 9) go 'up' to the calling code.
 9) repeat steps 7 and 8 util you reach 'your' code.
10) now 'continue' the program.  If it immediately segfaults, this was the
    offending call.  Otherwise, the program will stop aggain at another
    flockfile() invocation. repeat from step 7 -until- you get the segfault.

If, from that debugger session, you still don't see anything wrong, post
the log of the debugger session.

There is a *remote* possibility that the program will run properly under
the debugger, while it crashes when run directly.  This has been known 
to happen when a program _uses_ a variable before initializing it.

*IF* that happens, you will have to modify 'myprog' to add diagnostic
output before and after each identified point (above) in your code that
indirectly invokes flockfile() to find which is failing.  

In _that_ event, you =will= have to post the 'relevant' source-code from
'myprog', with the failing statement identified.

More information about the freebsd-questions mailing list