]> git.hungrycats.org Git - bees/commitdiff
bytevector: don't deadlock on operator<<
authorZygo Blaxell <bees@furryterror.org>
Wed, 4 Dec 2024 04:34:09 +0000 (23:34 -0500)
committerZygo Blaxell <bees@furryterror.org>
Wed, 4 Dec 2024 04:39:33 +0000 (23:39 -0500)
operator<< was a friend class that locked the ByteVector, then invoked
hexdump on the bytevector, which used ByteVector::operator[]...which
locked the ByteVector, resulting in a deadlock.

operator<< shouldn't be a friend class anyway.  Make hexdump use the
normal public access methods for ByteVector.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
include/crucible/bytevector.h
lib/bytevector.cc

index 469f3d170c193096a9e0830799532ba49abfdd8a..f68bcbd2d70a6b6618cd49a045da3e7f53c95587 100644 (file)
@@ -55,7 +55,6 @@ namespace crucible {
                Pointer m_ptr;
                size_t m_size = 0;
                mutable mutex m_mutex;
-       friend ostream & operator<<(ostream &os, const ByteVector &bv);
        };
 
        template <class T>
@@ -74,6 +73,8 @@ namespace crucible {
                THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T));
                return reinterpret_cast<T*>(data());
        }
+
+       ostream& operator<<(ostream &os, const ByteVector &bv);
 }
 
 #endif // _CRUCIBLE_BYTEVECTOR_H_
index 5cf5069ccefde6adcf50fc0c46b06c9cd635d5aa..9cbefd7cbc93935ac21a417c9cadb9f04d25fb3c 100644 (file)
@@ -183,7 +183,6 @@ namespace crucible {
 
        ostream&
        operator<<(ostream &os, const ByteVector &bv) {
-               unique_lock<mutex> lock(bv.m_mutex);
                hexdump(os, bv);
                return os;
        }