mirror of https://github.com/OISF/suricata
threads: add threadvars allocator and free func
Mostly meant to help unittests and fuzz targets alloc the storage
correctly.
(cherry picked from commit ad1459df72)
pull/16123/head
parent
098022aee5
commit
6a684e2ff5
@ -0,0 +1,48 @@
|
|||||||
|
/* Copyright (C) 2026 Open Information Security Foundation
|
||||||
|
*
|
||||||
|
* You can copy, redistribute or modify this Program under the terms of
|
||||||
|
* the GNU General Public License version 2 as published by the Free
|
||||||
|
* Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* version 2 along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "suricata-common.h"
|
||||||
|
#include "threadvars.h"
|
||||||
|
#include "thread-storage.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Allocate a new ThreadVars structure.
|
||||||
|
*
|
||||||
|
* \retval NULL if allocation failed.
|
||||||
|
* \retval Pointer to newly allocated ThreadVars structure.
|
||||||
|
*/
|
||||||
|
ThreadVars *ThreadVarsAlloc(void)
|
||||||
|
{
|
||||||
|
ThreadVars *tv = SCCalloc(1, sizeof(ThreadVars) + ThreadStorageSize());
|
||||||
|
if (tv == NULL)
|
||||||
|
return NULL;
|
||||||
|
SC_ATOMIC_INIT(tv->flags);
|
||||||
|
SCMutexInit(&tv->perf_public_ctx.m, NULL);
|
||||||
|
return tv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Free a ThreadVars structure.
|
||||||
|
*
|
||||||
|
* \param tv Pointer to ThreadVars structure to be freed.
|
||||||
|
*/
|
||||||
|
void ThreadVarsFree(ThreadVars *tv)
|
||||||
|
{
|
||||||
|
if (tv == NULL)
|
||||||
|
return;
|
||||||
|
SCFree(tv);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue