Skip to content

Commit c4a40c4

Browse files
committed
AsyncStreams: Refcount ZLibAPI
1 parent f020a3b commit c4a40c4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Libraries/AsyncStreams/Internal/ZLibAPI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ struct SC::ZLibAPI
119119
Error(SC_ZLIB_API_CC* pInflateInit2)(void* strm, int windowBits, const char* version, int stream_size) = nullptr;
120120
#undef SC_ZLIB_API_CC
121121
// Handle for dynamic library
122-
void* library = nullptr;
123-
122+
void* library = nullptr;
123+
int refCount = 0;
124124
struct Internal;
125125
};

Libraries/AsyncStreams/Internal/ZLibAPI.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ struct SC::ZLibAPI::Internal
7575
SC::Result SC::ZLibAPI::load(const char* libPath)
7676
{
7777
if (library != nullptr)
78+
{
79+
refCount++;
7880
return Result(true);
81+
}
7982
#if _WIN32
8083
const char* zlib_library_path = "zlib1.dll";
8184
#elif __APPLE__
@@ -112,11 +115,17 @@ SC::Result SC::ZLibAPI::load(const char* libPath)
112115
SC_TRY(Internal::loadSymbol(*this, pInflateEnd, "inflateEnd"));
113116
SC_TRY(Internal::loadSymbol(*this, pDeflateInit2, "deflateInit2_"));
114117
SC_TRY(Internal::loadSymbol(*this, pInflateInit2, "inflateInit2_"));
118+
refCount = 1;
115119
return Result(true);
116120
}
117121

118122
void SC::ZLibAPI::unload()
119123
{
124+
--refCount;
125+
if (refCount > 0)
126+
{
127+
return;
128+
}
120129
if (library)
121130
{
122131
#ifdef _WIN32

Libraries/AsyncStreams/Internal/ZLibStream.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ SC::ZLibStream::~ZLibStream()
147147
zlib.inflateEnd(stream);
148148
break;
149149
}
150+
zlib.unload();
150151
}
151152

152153
SC::Result SC::ZLibStream::init(Algorithm wantedAlgorithm)

0 commit comments

Comments
 (0)