]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Extend lockmgr to allow the use of destructor in pthread_key_create()
authorAlain Spineux <alain@baculasystems.com>
Fri, 3 Sep 2021 15:07:18 +0000 (17:07 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:04 +0000 (09:03 +0100)
- if a destructor use a lock then the lockmgr cannot find the thread
  (that is being destructed) anymore and fail to update the list
  for this thread.
- instead we check that we have a thread alive before to update it.
- TODO maybe we should also do the same check for other use of "self"
  in lockmgr.c

bacula/src/lib/lockmgr.c

index 4323e52263a29f946083ece7b53839a286a2f589..f9f17485d4b9d6f3c24c5b7e360ca62fab56a24a 100644 (file)
@@ -1022,9 +1022,9 @@ int bthread_mutex_unlock_p(bthread_mutex_t *m, const char *file, int line)
 int bthread_mutex_lock_p(pthread_mutex_t *m, const char *file, int line)
 {
    lmgr_thread_t *self = lmgr_get_thread_info();
-   self->pre_P(m, 0, file, line);
+   if (self) self->pre_P(m, 0, file, line);
    lmgr_p(m);
-   self->post_P();
+   if (self) self->post_P();
    return 0;
 }
 
@@ -1035,7 +1035,7 @@ int bthread_mutex_lock_p(pthread_mutex_t *m, const char *file, int line)
 int bthread_mutex_unlock_p(pthread_mutex_t *m, const char *file, int line)
 {
    lmgr_thread_t *self = lmgr_get_thread_info();
-   self->do_V(m, file, line);
+   if (self) self->do_V(m, file, line);
    lmgr_v(m);
    return 0;
 }