memory cleanup using abort()

memory cleanup using abort()

Post by Remco Poelstr » Thu, 19 Sep 2002 20:58:41



Hi,

I would like to use some functions from Glib, but I don't know how to
clean-up previousely allocated memory when Glib calls abort() in one of
it's functions due to a error.
More important is how I clean up my MySQL strcutures, which can't be
handled by the OS.
How do you people handle such situations?

Thanks in advance,

Remco Poelstra

 
 
 

memory cleanup using abort()

Post by Jens.Toerr.. » Thu, 19 Sep 2002 20:22:59



> I would like to use some functions from Glib, but I don't know how to
> clean-up previousely allocated memory when Glib calls abort() in one of
> it's functions due to a error.
> More important is how I clean up my MySQL strcutures, which can't be
> handled by the OS.

One thing you could try would be to catch SIGABRT and do the necessary
clean-up in the signal handler. While it's common knowledge that one
can't do much more reliably from within a signal handler than setting
a variable this may be a situation where you have no alternatives...

                                      Regards, Jens
--
      _  _____  _____

  _  | |  | |    | |
 | |_| |  | |    | |          http://www.physik.fu-berlin.de/~toerring
  \___/ens|_|homs|_|oerring

 
 
 

memory cleanup using abort()

Post by Eric Worral » Thu, 19 Sep 2002 20:56:50



> Hi,

> I would like to use some functions from Glib, but I don't know how to
> clean-up previousely allocated memory when Glib calls abort() in one of
> it's functions due to a error.
> More important is how I clean up my MySQL strcutures, which can't be
> handled by the OS.
> How do you people handle such situations?

> Thanks in advance,

> Remco Poelstra

The best way to handle this might be to use a parent / child
architecture. If your data structures are created in a child process,
killing the child returns all resources used by the child to the
operating system.

It doesn't matter if the child is connected to MySQL or whatever when it
dies. Tidyup because of a broken connection is a normal activity for
programs such as MySQL and should be handled correctly in all cases (if
not raise a bug report).

Eric Worrall

--
You have just received an Etech Solution
For all your Linux requirements contact

 
 
 

memory cleanup using abort()

Post by Eric P. McC » Thu, 19 Sep 2002 23:14:03



> I would like to use some functions from Glib, but I don't know how to
> clean-up previousely allocated memory when Glib calls abort() in one
> of it's functions due to a error.
> More important is how I clean up my MySQL strcutures, which can't be
> handled by the OS.
> How do you people handle such situations?

You shouldn't need to do anything explicitly to handle it.  MySQL
connections typically happen using sockets, either Unix or TCP/IP
ones, and the kernel will close all open sockets when your program is
terminated for any reason.  MySQL should correctly detect the peer end
of its socket has been closed and do whatever cleanup is necessary.
If it doesn't, that is a bug in MySQL, and your program should not be
trying to work around it.

If you are talking about "cleanup" in a more general sense - deleting
temporary tables and such - then what you really need to do is switch
to a database that supports transactions (in particular, rolling them
back).  You can often get away with doing complex cleanup in signal
handlers, which makes it great for temporary hacks, but it's by no
means a solution.

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj