Repository: mesos Updated Branches: refs/heads/master 5a4094b36 -> e469815db
Fixed a resource leak in ThreadLocal. Review: https://reviews.apache.org/r/24669 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e469815d Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e469815d Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e469815d Branch: refs/heads/master Commit: e469815dbe27b401865ffa6c2cc3d41ff3941ada Parents: 5a4094b Author: Benjamin Mahler <[email protected]> Authored: Wed Aug 13 14:36:26 2014 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Wed Aug 13 14:56:48 2014 -0700 ---------------------------------------------------------------------- .../3rdparty/stout/include/stout/thread.hpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e469815d/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp index a20df86..b1af74f 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/thread.hpp @@ -14,6 +14,7 @@ #ifndef __STOUT_THREAD_HPP__ #define __STOUT_THREAD_HPP__ +#include <errno.h> #include <pthread.h> #include <stdio.h> // For perror. #include <stdlib.h> // For abort. @@ -23,15 +24,29 @@ struct ThreadLocal { ThreadLocal() { - if (pthread_key_create(&key, NULL) != 0) { + errno = pthread_key_create(&key, NULL); + + if (errno != 0) { perror("Failed to create thread local, pthread_key_create"); abort(); } } + ~ThreadLocal() + { + errno = pthread_key_delete(key); + + if (errno != 0) { + perror("Failed to destruct thread local, pthread_key_delete"); + abort(); + } + } + ThreadLocal<T>& operator = (T* t) { - if (pthread_setspecific(key, t) != 0) { + errno = pthread_setspecific(key, t); + + if (errno != 0) { perror("Failed to set thread local, pthread_setspecific"); abort(); }
