From c49c235c932f1c1187fb2b089a12a31b403ac381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 30 Apr 2013 00:36:16 -0400 Subject: [PATCH] libwinpr-utils: fix stream pool --- libfreerdp/core/message.c | 2 +- winpr/libwinpr/utils/collections/StreamPool.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index 3ccea28d3..0c27bd5e2 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -31,7 +31,7 @@ #include #include -//#define WITH_STREAM_POOL 1 +#define WITH_STREAM_POOL 1 /* Update */ diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c index 69e0049bf..fe5e3bc27 100644 --- a/winpr/libwinpr/utils/collections/StreamPool.c +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -44,7 +44,7 @@ void StreamPool_ShiftUsed(wStreamPool* pool, int index, int count) } else if (count < 0) { - MoveMemory(&pool->uArray[index], &pool->uArray[index - count], (pool->uSize + count) * sizeof(wStream*)); + MoveMemory(&pool->uArray[index], &pool->uArray[index - count], (pool->uSize - index) * sizeof(wStream*)); pool->uSize += count; } } @@ -101,7 +101,7 @@ void StreamPool_ShiftAvailable(wStreamPool* pool, int index, int count) } else if (count < 0) { - MoveMemory(&pool->aArray[index], &pool->aArray[index - count], (pool->aSize + count) * sizeof(wStream*)); + MoveMemory(&pool->aArray[index], &pool->aArray[index - count], (pool->aSize - index) * sizeof(wStream*)); pool->aSize += count; } } @@ -113,6 +113,7 @@ void StreamPool_ShiftAvailable(wStreamPool* pool, int index, int count) wStream* StreamPool_Take(wStreamPool* pool, size_t size) { int index; + int foundIndex; wStream* s = NULL; BOOL found = FALSE; @@ -128,7 +129,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) if (s->capacity >= size) { - StreamPool_ShiftAvailable(pool, index, -1); + foundIndex = index; found = TRUE; break; } @@ -140,6 +141,8 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size) } else { + StreamPool_ShiftAvailable(pool, foundIndex, -1); + Stream_EnsureCapacity(s, size); Stream_Pointer(s) = Stream_Buffer(s); }