Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!hellgate.utah.edu!cs.utexas.edu!wuarchive!texbell!nuchat!sugar!ficc!peter From: peter@ficc.uu.net (peter da silva) Newsgroups: comp.lang.c Subject: Re: Using setjmp/longjmp Message-ID: <-3B3VV9xds13@ficc.uu.net> Date: 8 May 90 16:03:53 GMT References: <735@mwtech.UUCP> <0654@sheol.UUCP> <2432@skye.ed.ac.uk> Organization: Ferranti International Controls Corporation Lines: 19 > I think the poster meant that it's difficult to use longjmp() to abort > to your program's main loop and at the same time clean up memory > allocated "on the way down". Rather than make this specific to longjmp, I tend to use a function called "add_cleanup". This is passed a function name and a pointer to a single argument, then when I want to clean things up I call cleanup(), which pops all the functions off the stack and executes them in turn. For example: if(memory = malloc(...)) { add_cleanup(free, memory); ... } else { errmsg = "Out of memory in foobar"; longjmp(restart); } -- `-_-' Peter da Silva. +1 713 274 5180. 'U` Have you hugged your wolf today? @FIN Commercial solicitation *is* accepted by email to this address.