util/varname: check id before unregister

In case of an error a varname id is set to 0. Ideally, it shouldn't be
found in the hash table lookup but add a check anyway to avoid obtaining
the mutex lock and performing the lookup.
pull/14262/head
Shivani Bhardwaj 9 months ago committed by Victor Julien
parent ec65fd430e
commit e5994deb23

@ -203,6 +203,10 @@ const char *VarNameStoreSetupLookup(const uint32_t id, const enum VarTypes type)
void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type) void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
{ {
if (unlikely(id == 0)) {
/* There was an error registering the varname, so nothing to unregister */
return;
}
SCMutexLock(&base_lock); SCMutexLock(&base_lock);
VariableName lookup = { .type = type, .id = id }; VariableName lookup = { .type = type, .id = id };
VariableName *found = (VariableName *)HashListTableLookup(base.ids, (void *)&lookup, 0); VariableName *found = (VariableName *)HashListTableLookup(base.ids, (void *)&lookup, 0);

Loading…
Cancel
Save