mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
Remove pointless storage of var names in virNWFilterHashTable
The virNWFilterHashTable struct contains a virHashTable and then a 'char **names' field which keeps a copy of all the hash keys. Presumably this was intended to record the ordering of the hash keys. No code ever uses this and the ordering is mangled whenever a variable is removed from the hash, because the last element in the list is copied into the middle of the list when shrinking the array. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
50859fc1dd
commit
293d4fe2f1
@ -60,7 +60,7 @@ virNWFilterIPAddrMapAddIPAddr(const char *ifname, char *addr)
|
||||
val = virNWFilterVarValueCreateSimple(addr);
|
||||
if (!val)
|
||||
goto cleanup;
|
||||
ret = virNWFilterHashTablePut(ipAddressMap, ifname, val, 1);
|
||||
ret = virNWFilterHashTablePut(ipAddressMap, ifname, val);
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (virNWFilterVarValueAddValue(val, addr) < 0)
|
||||
|
@ -631,33 +631,14 @@ hashDataFree(void *payload, const void *name ATTRIBUTE_UNUSED)
|
||||
int
|
||||
virNWFilterHashTablePut(virNWFilterHashTablePtr table,
|
||||
const char *name,
|
||||
virNWFilterVarValuePtr val,
|
||||
int copyName)
|
||||
virNWFilterVarValuePtr val)
|
||||
{
|
||||
if (!virHashLookup(table->hashTable, name)) {
|
||||
char *newName;
|
||||
if (copyName) {
|
||||
if (VIR_STRDUP(newName, name) < 0)
|
||||
return -1;
|
||||
|
||||
if (VIR_APPEND_ELEMENT_COPY(table->names,
|
||||
table->nNames, newName) < 0) {
|
||||
VIR_FREE(newName);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (virHashAddEntry(table->hashTable, name, val) < 0) {
|
||||
if (copyName) {
|
||||
VIR_FREE(newName);
|
||||
table->nNames--;
|
||||
}
|
||||
if (virHashAddEntry(table->hashTable, name, val) < 0)
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (virHashUpdateEntry(table->hashTable, name, val) < 0) {
|
||||
if (virHashUpdateEntry(table->hashTable, name, val) < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -675,14 +656,10 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
|
||||
void
|
||||
virNWFilterHashTableFree(virNWFilterHashTablePtr table)
|
||||
{
|
||||
size_t i;
|
||||
if (!table)
|
||||
return;
|
||||
virHashFree(table->hashTable);
|
||||
|
||||
for (i = 0; i < table->nNames; i++)
|
||||
VIR_FREE(table->names[i]);
|
||||
VIR_FREE(table->names);
|
||||
VIR_FREE(table);
|
||||
}
|
||||
|
||||
@ -707,20 +684,7 @@ void *
|
||||
virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr ht,
|
||||
const char *entry)
|
||||
{
|
||||
size_t i;
|
||||
void *value = virHashSteal(ht->hashTable, entry);
|
||||
|
||||
if (value) {
|
||||
for (i = 0; i < ht->nNames; i++) {
|
||||
if (STREQ(ht->names[i], entry)) {
|
||||
VIR_FREE(ht->names[i]);
|
||||
ht->names[i] = ht->names[--ht->nNames];
|
||||
ht->names[ht->nNames] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
return virHashSteal(ht->hashTable, entry);
|
||||
}
|
||||
|
||||
|
||||
@ -745,7 +709,7 @@ addToTable(void *payload, const void *name, void *data)
|
||||
return;
|
||||
}
|
||||
|
||||
if (virNWFilterHashTablePut(atts->target, (const char *)name, val, 1) < 0){
|
||||
if (virNWFilterHashTablePut(atts->target, (const char *)name, val) < 0){
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Could not put variable '%s' into hashmap"),
|
||||
(const char *)name);
|
||||
@ -850,7 +814,7 @@ virNWFilterParseParamAttributes(xmlNodePtr cur)
|
||||
value = virNWFilterParseVarValue(val);
|
||||
if (!value)
|
||||
goto skip_entry;
|
||||
if (virNWFilterHashTablePut(table, nam, value, 1) < 0)
|
||||
if (virNWFilterHashTablePut(table, nam, value) < 0)
|
||||
goto err_exit;
|
||||
}
|
||||
value = NULL;
|
||||
|
@ -66,9 +66,6 @@ typedef struct _virNWFilterHashTable virNWFilterHashTable;
|
||||
typedef virNWFilterHashTable *virNWFilterHashTablePtr;
|
||||
struct _virNWFilterHashTable {
|
||||
virHashTablePtr hashTable;
|
||||
|
||||
size_t nNames;
|
||||
char **names;
|
||||
};
|
||||
|
||||
|
||||
@ -81,8 +78,7 @@ virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
|
||||
void virNWFilterHashTableFree(virNWFilterHashTablePtr table);
|
||||
int virNWFilterHashTablePut(virNWFilterHashTablePtr table,
|
||||
const char *name,
|
||||
virNWFilterVarValuePtr val,
|
||||
int freeName);
|
||||
virNWFilterVarValuePtr val);
|
||||
void *virNWFilterHashTableRemoveEntry(virNWFilterHashTablePtr table,
|
||||
const char *name);
|
||||
int virNWFilterHashTablePutAll(virNWFilterHashTablePtr src,
|
||||
|
@ -512,7 +512,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
|
||||
|
||||
varAccess = virBufferContentAndReset(&buf);
|
||||
virNWFilterHashTablePut(missing_vars, varAccess,
|
||||
val, 1);
|
||||
val);
|
||||
VIR_FREE(varAccess);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user