/* Used by l7inspection to return msgs to pool */ void StreamMsgReturnToPool(StreamMsg *s) { SCLogDebug("s %p", s); SCMutexLock(&stream_msg_pool_mutex); PoolReturn(stream_msg_pool, (void *)s); SCMutexUnlock(&stream_msg_pool_mutex); }
static void DetectLuajitReturnState(lua_State *s) { if (s != NULL) { pthread_mutex_lock(&luajit_states_lock); PoolReturn(luajit_states, (void *)s); pthread_mutex_unlock(&luajit_states_lock); } }
static int PoolTestInit06 (void) { int retval = 0; void *data = NULL; void *data2 = NULL; Pool *p = PoolInit(1,0,PoolTestAlloc,NULL,PoolTestFree); if (p == NULL) goto end; if (p->allocated != 0) { printf("p->allocated 0 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } data = PoolGet(p); if (data == NULL) { printf("PoolGet returned NULL: "); retval = 0; goto end; } if (p->allocated != 1) { printf("p->allocated 1 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } data2 = PoolGet(p); if (data2 != NULL) { printf("PoolGet returned %p, expected NULL: ", data2); retval = 0; goto end; } PoolReturn(p,data); data = NULL; if (p->allocated != 1) { printf("p->allocated 1 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } if (p->alloc_list_size != 1) { printf("p->alloc_list_size 1 != %" PRIu32 ": ", p->alloc_list_size); retval = 0; goto end; } retval = 1; end: if (data != NULL) SCFree(data); if (data2 != NULL) SCFree(data2); if (p != NULL) PoolFree(p); return retval; }
void PoolThreadReturn(PoolThread *pt, void *data) { PoolThreadReserved *id = data; if (pt == NULL || *id >= pt->size) return; SCLogDebug("returning to id %u", *id); PoolThreadElement *e = &pt->array[*id]; SCMutexLock(&e->lock); PoolReturn(e->pool, data); SCMutexUnlock(&e->lock); }
static int PoolTestInit05 (void) { int retval = 0; void *data = NULL; Pool *p = PoolInit(10,5,PoolTestAlloc,NULL,PoolTestFree); if (p == NULL) goto end; data = PoolGet(p); if (data == NULL) { printf("PoolGet returned NULL: "); retval = 0; goto end; } if (p->alloc_list_size != 4) { printf("p->alloc_list_size 4 != %" PRIu32 ": ", p->alloc_list_size); retval = 0; goto end; } if (p->empty_list_size != 6) { printf("p->empty_list_size 6 != %" PRIu32 ": ", p->empty_list_size); retval = 0; goto end; } PoolReturn(p, data); data = NULL; if (p->alloc_list_size != 5) { printf("p->alloc_list_size 5 != %" PRIu32 ": ", p->alloc_list_size); retval = 0; goto end; } if (p->empty_list_size != 5) { printf("p->empty_list_size 5 != %" PRIu32 ": ", p->empty_list_size); retval = 0; goto end; } retval = 1; end: if (data != NULL) SCFree(data); if (p != NULL) PoolFree(p); return retval; }
static void mimeTypeAdd(MIMEType * const MIMETypeP, const char * const type, const char * const ext, bool * const successP) { uint16_t index; void * mimeTypesItem; bool typeIsInList; assert(MIMETypeP != NULL); typeIsInList = ListFindString(&MIMETypeP->typeList, type, &index); if (typeIsInList) mimeTypesItem = MIMETypeP->typeList.item[index]; else mimeTypesItem = (void*)PoolStrdup(&MIMETypeP->pool, type); if (mimeTypesItem) { bool extIsInList; extIsInList = ListFindString(&MIMETypeP->extList, ext, &index); if (extIsInList) { MIMETypeP->typeList.item[index] = mimeTypesItem; *successP = TRUE; } else { void * extItem = (void*)PoolStrdup(&MIMETypeP->pool, ext); if (extItem) { bool addedToMimeTypes; addedToMimeTypes = ListAdd(&MIMETypeP->typeList, mimeTypesItem); if (addedToMimeTypes) { bool addedToExt; addedToExt = ListAdd(&MIMETypeP->extList, extItem); *successP = addedToExt; if (!*successP) ListRemove(&MIMETypeP->typeList); } else *successP = FALSE; if (!*successP) PoolReturn(&MIMETypeP->pool, extItem); } else *successP = FALSE; } } else *successP = FALSE; }
/** \test pool with unlimited size */ static int PoolTestInit07 (void) { int retval = 0; void *data = NULL; void *data2 = NULL; Pool *p = PoolInit(0,1,10,PoolTestAlloc,NULL,NULL,PoolTestFree); if (p == NULL) goto end; if (p->max_buckets != 0) { printf("p->max_buckets 0 != %" PRIu32 ": ", p->max_buckets); retval = 0; goto end; } if (p->allocated != 1) { printf("p->allocated 1 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } data = PoolGet(p); if (data == NULL) { printf("PoolGet returned NULL: "); retval = 0; goto end; } if (p->allocated != 1) { printf("(2) p->allocated 1 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } data2 = PoolGet(p); if (data2 == NULL) { printf("PoolGet returned NULL: "); retval = 0; goto end; } if (p->allocated != 2) { printf("(3) p->allocated 2 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } PoolReturn(p,data); data = NULL; if (p->allocated != 2) { printf("(4) p->allocated 2 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } if (p->alloc_list_size != 1) { printf("p->alloc_list_size 1 != %" PRIu32 ": ", p->alloc_list_size); retval = 0; goto end; } PoolReturn(p,data2); data2 = NULL; if (p->allocated != 1) { printf("(5) p->allocated 1 != %" PRIu32 ": ", p->allocated); retval = 0; goto end; } retval = 1; end: if (p != NULL) PoolFree(p); return retval; }