Skip to content

Commit

Permalink
Gracefully handle unexpected calls to exit().
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Nov 21, 2015
1 parent 0a54f94 commit e813d27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/audacious/main.cc
Expand Up @@ -49,6 +49,7 @@ static struct {
int qt;
} options;

static bool initted = false;
static Index<PlaylistAddItem> filenames;

static const struct {
Expand Down Expand Up @@ -304,6 +305,17 @@ static void do_commands ()

static void main_cleanup ()
{
if (initted)
{
/* Somebody was naughty and called exit() instead of aud_quit().
* aud_cleanup() has not been called yet, so there's no point in running
* leak checks. Note that it's not safe to call aud_cleanup() from the
* exit handler, since we don't know what context we're in (we could be
* deep inside the call tree of some plugin, for example). */
AUDWARN ("exit() called unexpectedly; skipping normal cleanup.\n");
return;
}

filenames.clear ();
aud_cleanup_paths ();
aud_leak_check ();
Expand Down Expand Up @@ -360,6 +372,7 @@ int main (int argc, char * * argv)
signals_init_two ();
#endif

initted = true;
aud_init ();

do_commands ();
Expand All @@ -383,6 +396,7 @@ int main (int argc, char * * argv)
#endif

aud_cleanup ();
initted = false;

return EXIT_SUCCESS;
}
17 changes: 14 additions & 3 deletions src/libaudcore/multihash.h
Expand Up @@ -54,8 +54,11 @@ class HashBase
size (0),
used (0) {}

~HashBase ()
{ delete[] buckets; }
void clear () // use as destructor
{
delete[] buckets;
* this = HashBase ();
}

int n_items () const
{ return used; }
Expand Down Expand Up @@ -112,6 +115,11 @@ class MultiHash
locks (),
channels () {}

/* There is no destructor. In some instances, such as the string pool, it
* is never safe to destroy the hash table, since it can be referenced from
* the destructors of other static objects. It is left to the operating
* system to reclaim the memory used by the hash table upon process exit. */

/* All-purpose lookup function. The caller passes in the data to be looked
* up along with its hash value. The two callbacks are optional. <add> is
* called if no matching node is found, and may return a new node to add to
Expand Down Expand Up @@ -187,7 +195,10 @@ class SimpleHash : private HashBase
}

void clear ()
{ HashBase::iterate (remove_cb, nullptr); }
{
HashBase::iterate (remove_cb, nullptr);
HashBase::clear ();
}

private:
struct Node : public HashBase::Node
Expand Down

0 comments on commit e813d27

Please sign in to comment.