diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index e59f07217..b2c6c3b41 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -25,6 +25,8 @@ #include #include "../stream.h" +#include "../log.h" +#define TAG WINPR_TAG("utils.streampool") struct s_StreamPoolEntry { @@ -368,10 +370,15 @@ void StreamPool_Clear(wStreamPool* pool) discard_entry(cur, TRUE); } - for (size_t x = 0; x < pool->uSize; x++) + if (pool->uSize > 0) { - struct s_StreamPoolEntry* cur = &pool->uArray[x]; - discard_entry(cur, TRUE); + WLog_WARN(TAG, "Clearing StreamPool, but there are %" PRIuz " streams currently in use", + pool->uSize); + for (size_t x = 0; x < pool->uSize; x++) + { + struct s_StreamPoolEntry* cur = &pool->uArray[x]; + discard_entry(cur, TRUE); + } } StreamPool_Unlock(pool); @@ -441,7 +448,7 @@ char* StreamPool_GetStatistics(wStreamPool* pool, char* buffer, size_t size) size_t used = 0; int offset = _snprintf(buffer, size - 1, - "aSize =%" PRIuz ", uSize =%" PRIuz "aCapacity=%" PRIuz + "aSize =%" PRIuz ", uSize =%" PRIuz ", aCapacity=%" PRIuz ", uCapacity=%" PRIuz, pool->aSize, pool->uSize, pool->aCapacity, pool->uCapacity); if ((offset > 0) && (offset < size)) @@ -466,6 +473,25 @@ char* StreamPool_GetStatistics(wStreamPool* pool, char* buffer, size_t size) used += (size_t)offset; } } + + offset = _snprintf(&buffer[used], size - 1 - used, "\n-- statistics called from --\n"); + if ((offset > 0) && (offset < size - used)) + used += (size_t)offset; + + struct s_StreamPoolEntry entry = { 0 }; + void* stack = winpr_backtrace(20); + if (stack) + entry.msg = winpr_backtrace_symbols(stack, &entry.lines); + winpr_backtrace_free(stack); + + for (size_t x = 0; x < entry.lines; x++) + { + const char* msg = entry.msg[x]; + offset = _snprintf(&buffer[used], size - 1 - used, "[%" PRIuz "]: %s\n", x, msg); + if ((offset > 0) && (offset < size - used)) + used += (size_t)offset; + } + free((void*)entry.msg); StreamPool_Unlock(pool); #endif buffer[used] = '\0'; diff --git a/winpr/libwinpr/utils/test/TestStreamPool.c b/winpr/libwinpr/utils/test/TestStreamPool.c index 1844a531c..615a5ac9b 100644 --- a/winpr/libwinpr/utils/test/TestStreamPool.c +++ b/winpr/libwinpr/utils/test/TestStreamPool.c @@ -72,6 +72,10 @@ int TestStreamPool(int argc, char* argv[]) printf("%s\n", StreamPool_GetStatistics(pool, buffer, sizeof(buffer))); + Stream_Release(s[2]); + Stream_Release(s[3]); + Stream_Release(s[4]); + StreamPool_Free(pool); return 0;