pool: use errno style error reporting

pull/8304/head
Victor Julien 3 years ago
parent e621416d80
commit 8ef95c10a8

@ -553,7 +553,8 @@ TcpReassemblyThreadCtx *StreamTcpReassembleInitThreadCtx(ThreadVars *tv)
}
SCMutexUnlock(&segment_thread_pool_mutex);
if (ra_ctx->segment_thread_pool_id < 0 || segment_thread_pool == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "failed to setup/expand stream segment pool. Expand stream.reassembly.memcap?");
SCLogError(sc_errno,
"failed to setup/expand stream segment pool. Expand stream.reassembly.memcap?");
StreamTcpReassembleFreeThreadCtx(ra_ctx);
SCReturnPtr(NULL, "TcpReassemblyThreadCtx");
}

@ -5466,7 +5466,7 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
}
SCMutexUnlock(&ssn_pool_mutex);
if (stt->ssn_pool_id < 0 || ssn_pool == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "failed to setup/expand stream session pool. Expand stream.memcap?");
SCLogError(sc_errno, "failed to setup/expand stream session pool. Expand stream.memcap?");
SCReturnInt(TM_ECODE_FAILED);
}

@ -103,8 +103,7 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_ARG_LEN_LONG);
CASE_CODE (SC_ERR_ALPARSER);
CASE_CODE (SC_ERR_POOL_EMPTY);
CASE_CODE (SC_ERR_REASSEMBLY);
CASE_CODE (SC_ERR_POOL_INIT);
CASE_CODE(SC_ERR_REASSEMBLY);
CASE_CODE (SC_ERR_UNIMPLEMENTED);
CASE_CODE (SC_ERR_ADDRESS_ENGINE_GENERIC);
CASE_CODE (SC_ERR_PORT_ENGINE_GENERIC);

@ -96,7 +96,6 @@ typedef enum {
SC_ERR_ARG_LEN_LONG,
SC_ERR_POOL_EMPTY,
SC_ERR_REASSEMBLY,
SC_ERR_POOL_INIT,
SC_ERR_NFQ_NOSUPPORT,
SC_ERR_NFQ_OPEN,
SC_ERR_NFQ_BIND,

@ -44,14 +44,18 @@ PoolThread *PoolThreadInit(int threads, uint32_t size, uint32_t prealloc_size,
uint32_t elt_size, void *(*Alloc)(void), int (*Init)(void *, void *),
void *InitData, void (*Cleanup)(void *), void (*Free)(void *))
{
sc_errno = SC_OK;
if (threads <= 0) {
SCLogDebug("error");
sc_errno = SC_EINVAL;
return NULL;
}
PoolThread *pt = SCCalloc(1, sizeof(*pt));
if (unlikely(pt == NULL)) {
SCLogDebug("memory alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
@ -59,6 +63,7 @@ PoolThread *PoolThreadInit(int threads, uint32_t size, uint32_t prealloc_size,
pt->array = SCMalloc(threads * sizeof(PoolThreadElement));
if (pt->array == NULL) {
SCLogDebug("memory alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
pt->size = threads;
@ -92,7 +97,7 @@ error:
int PoolThreadExpand(PoolThread *pt)
{
if (pt == NULL || pt->array == NULL || pt->size == 0) {
SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
SCLogError(SC_EINVAL, "pool grow failed");
return -1;
}
@ -103,7 +108,7 @@ int PoolThreadExpand(PoolThread *pt)
if (ptmp == NULL) {
SCFree(pt->array);
pt->array = NULL;
SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
SCLogError(SC_EINVAL, "pool grow failed");
return -1;
}
pt->array = ptmp;
@ -133,7 +138,7 @@ int PoolThreadExpand(PoolThread *pt)
settings.Cleanup, settings.Free);
SCMutexUnlock(&e->lock);
if (e->pool == NULL) {
SCLogError(SC_ERR_POOL_INIT, "pool grow failed");
SCLogError(SC_EINVAL, "pool grow failed");
return -1;
}

@ -85,25 +85,27 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
void *(*Alloc)(void), int (*Init)(void *, void *), void *InitData,
void (*Cleanup)(void *), void (*Free)(void *))
{
sc_errno = SC_OK;
Pool *p = NULL;
if (size != 0 && prealloc_size > size) {
SCLogError(SC_ERR_POOL_INIT, "size error");
sc_errno = SC_EINVAL;
goto error;
}
if (size != 0 && elt_size == 0) {
SCLogError(SC_ERR_POOL_INIT, "size != 0 && elt_size == 0");
sc_errno = SC_EINVAL;
goto error;
}
if (elt_size && Free) {
SCLogError(SC_ERR_POOL_INIT, "elt_size && Free");
sc_errno = SC_EINVAL;
goto error;
}
/* setup the filter */
p = SCMalloc(sizeof(Pool));
if (unlikely(p == NULL)) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
@ -128,7 +130,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
if (size > 0) {
PoolBucket *pb = SCCalloc(size, sizeof(PoolBucket));
if (unlikely(pb == NULL)) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
memset(pb, 0, size * sizeof(PoolBucket));
@ -145,7 +147,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
p->data_buffer = SCCalloc(prealloc_size, elt_size);
/* FIXME better goto */
if (p->data_buffer == NULL) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
}
@ -154,7 +156,7 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
if (size == 0) { /* unlimited */
PoolBucket *pb = SCMalloc(sizeof(PoolBucket));
if (unlikely(pb == NULL)) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
memset(pb, 0, sizeof(PoolBucket));
@ -165,17 +167,17 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
pb->data = SCMalloc(p->elt_size);
}
if (pb->data == NULL) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
SCFree(pb);
sc_errno = SC_ENOMEM;
goto error;
}
if (p->Init(pb->data, p->InitData) != 1) {
SCLogError(SC_ERR_POOL_INIT, "init error");
if (p->Free)
p->Free(pb->data);
else
SCFree(pb->data);
SCFree(pb);
sc_errno = SC_EINVAL;
goto error;
}
p->allocated++;
@ -186,14 +188,14 @@ Pool *PoolInit(uint32_t size, uint32_t prealloc_size, uint32_t elt_size,
} else {
PoolBucket *pb = p->empty_stack;
if (pb == NULL) {
SCLogError(SC_ERR_POOL_INIT, "alloc error");
sc_errno = SC_ENOMEM;
goto error;
}
pb->data = (char *)p->data_buffer + u32 * elt_size;
if (p->Init(pb->data, p->InitData) != 1) {
SCLogError(SC_ERR_POOL_INIT, "init error");
pb->data = NULL;
sc_errno = SC_EINVAL;
goto error;
}

Loading…
Cancel
Save