threaded fixes with static memory

This commit is contained in:
Jacob Barthelmeh
2016-06-10 15:35:02 -06:00
parent 3d3591a227
commit 707714dd38
2 changed files with 18 additions and 4 deletions

View File

@@ -3135,16 +3135,16 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
if (ctx_hint->memory->maxHa > 0 &&
ctx_hint->memory->maxHa <= ctx_hint->memory->curHa) {
WOLFSSL_MSG("At max number of handshakes for static memory");
UnLockMutex(&(ctx_hint->memory->memory_mutex));
return MEMORY_E;
}
ctx_hint->memory->curHa++;
if (ctx_hint->memory->maxIO > 0 &&
ctx_hint->memory->maxIO <= ctx_hint->memory->curIO) {
WOLFSSL_MSG("At max number of IO allowed for static memory");
UnLockMutex(&(ctx_hint->memory->memory_mutex));
return MEMORY_E;
}
ctx_hint->memory->curIO++;
UnLockMutex(&(ctx_hint->memory->memory_mutex));
ssl->heap = (WOLFSSL_HEAP_HINT*)XMALLOC(sizeof(WOLFSSL_HEAP_HINT),
@@ -3173,17 +3173,29 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
return BAD_MUTEX_E;
}
if (SetFixedIO(ctx_hint->memory, &(ssl_hint->inBuf)) != 1) {
UnLockMutex(&(ctx_hint->memory->memory_mutex));
return MEMORY_E;
}
if (SetFixedIO(ctx_hint->memory, &(ssl_hint->outBuf)) != 1) {
UnLockMutex(&(ctx_hint->memory->memory_mutex));
return MEMORY_E;
}
if (ssl_hint->outBuf == NULL || ssl_hint->inBuf == NULL) {
WOLFSSL_MSG("Not enough memory to create fixed IO buffers");
UnLockMutex(&(ctx_hint->memory->memory_mutex));
return MEMORY_E;
}
UnLockMutex(&(ctx_hint->memory->memory_mutex));
}
/* increment counters at end of setting up memory */
if (LockMutex(&(ctx_hint->memory->memory_mutex)) != 0) {
WOLFSSL_MSG("Bad memory_mutex lock");
return BAD_MUTEX_E;
}
ctx_hint->memory->curHa++;
ctx_hint->memory->curIO++;
UnLockMutex(&(ctx_hint->memory->memory_mutex));
#ifdef WOLFSSL_HEAP_TEST
}
#endif

View File

@@ -493,8 +493,10 @@ void wolfSSL_Free(void *ptr, void* heap, int type)
/* get memory struct and add it to available list */
pt = (wc_Memory*)((byte*)ptr - sizeof(wc_Memory) - padSz);
LockMutex(&(mem->memory_mutex));
if (LockMutex(&(mem->memory_mutex)) != 0) {
WOLFSSL_MSG("Bad memory_mutex lock");
return;
}
/* case of using fixed IO buffers */
if (mem->flag & WOLFMEM_IO_POOL_FIXED &&