From 5b82342c90a68b513a3116f5844062f4131ea5ab Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 23 Aug 2004 15:22:46 +0000 Subject: [PATCH] (destroy_dotlock): Remove the handle from the list of locks. (release_dotlock): Don't act if we don't have any locks at all. --- util/ChangeLog | 10 ++++++++++ util/dotlock.c | 31 +++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/util/ChangeLog b/util/ChangeLog index d31de6a59..35f4ad72b 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,13 @@ +2004-08-23 Werner Koch + + * dotlock.c (destroy_dotlock): Remove the handle from the list of + locks. + (release_dotlock): Don't act if we don't have any locks at all. + +2004-08-19 Werner Koch + + * dotlock.c (destroy_dotlock): Don't act on NULL filenames. + 2004-08-19 David Shaw * http.c (insert_escapes): Fix encoding problem for non-URI-safe diff --git a/util/dotlock.c b/util/dotlock.c index f28b0e409..16eb4d005 100644 --- a/util/dotlock.c +++ b/util/dotlock.c @@ -204,15 +204,32 @@ destroy_dotlock ( DOTLOCK h ) #if !defined (HAVE_DOSISH_SYSTEM) if ( h ) { + DOTLOCK hprev, htmp; + + /* First remove the handle from our global list of all locks. */ + for (hprev=NULL, htmp=all_lockfiles; htmp; hprev=htmp, htmp=htmp->next) + if (htmp == h) + { + if (hprev) + hprev->next = htmp->next; + else + all_lockfiles = htmp->next; + h->next = NULL; + break; + } + + /* Second destroy the lock. */ if (!h->disable) { - if (h->locked) + if (h->locked && h->lockname) unlink (h->lockname); - unlink (h->tname); + if (h->tname) + unlink (h->tname); m_free (h->tname); m_free (h->lockname); } m_free(h); + } #endif } @@ -339,9 +356,15 @@ release_dotlock( DOTLOCK h ) #else int pid; - if( h->disable ) { + /* To avoid atexit race conditions we first check whether there + are any locks left. It might happen that another atexit + handler tries to release the lock while the atexit handler of + this module already ran and thus H is undefined. */ + if(!all_lockfiles) + return 0; + + if( h->disable ) return 0; - } if( !h->locked ) { log_debug("oops, `%s' is not locked\n", h->lockname );