[Gllug] My and my malloc() problems....

tet at accucard.com tet at accucard.com
Sun Dec 30 22:45:11 UTC 2001


>This is likely only the case if longjmp() is being used, and that little
>horror should be used as little as possible, IMHO.

I've seen this said many times. Can someone explain:

1. why setjmp()/longjmp() are so frowned upon
2. what can be used to replace them

I've used them in the past for RPC programming where not all the calls
had timeouts. So I manually hacked together a timeout using setjmp(),
longjmp() and interval timers. If the interval timer fires, then rewind
the stack using longjmp(), and handle the error. Lo and behold, a homemade
timeout on the call.

So what could/should I have done differently in that situation [1]?

BTW, it looks like I was saving signals manually, as I wasn't aware
of sig{set,long}jmp() at the time...

I can see that it makes the code harder to follow, and also more prone
to error (for example, memory allocation has to be tracked and released
where necessary, which some people are bound to forget), but nothing
that's actually *bad*. So why the poor reputation?

Tet

[1] Looking back at the code in question, I was using it for clnt_create().
    The man page claims that timeouts can be set with clnt_control(), but
    I'm sure that either wasn't the case, or wasn't documented at the time
    I wrote it (1995, according to the SCCS logs). For the sake of argument,
    though, assume any generic library call that doesn't have a timeout but
    needs one.

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list