virlog: Introduce virLogOutputListFree

This is just a convenience method for discarding a list of outputs instead of
using a 'for' loop everywhere. It is safe to pass -1 as the number of elements
in the list as well as passing NULL as list reference.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2016-03-30 14:11:12 +02:00
parent 057788c537
commit 4b48541249
3 changed files with 26 additions and 6 deletions

View File

@ -1823,6 +1823,7 @@ virLogGetOutputs;
virLogLock;
virLogMessage;
virLogOutputFree;
virLogOutputListFree;
virLogParseDefaultPriority;
virLogParseFilters;
virLogParseOutputs;

View File

@ -325,12 +325,8 @@ virLogDefineFilter(const char *match,
static void
virLogResetOutputs(void)
{
size_t i;
for (i = 0; i < virLogNbOutputs; i++)
virLogOutputFree(virLogOutputs[i]);
VIR_FREE(virLogOutputs);
virLogOutputListFree(virLogOutputs, virLogNbOutputs);
virLogOutputs = NULL;
virLogNbOutputs = 0;
}
@ -348,6 +344,28 @@ virLogOutputFree(virLogOutputPtr output)
}
/**
* virLogOutputsFreeList:
* @list: list of outputs to be freed
* @count: number of elements in the list
*
* Frees a list of outputs.
*/
void
virLogOutputListFree(virLogOutputPtr *list, int count)
{
size_t i;
if (!list || count < 0)
return;
for (i = 0; i < count; i++)
virLogOutputFree(list[i]);
VIR_FREE(list);
}
/**
* virLogDefineOutput:
* @f: the function to call to output a message

View File

@ -191,6 +191,7 @@ int virLogDefineOutput(virLogOutputFunc f,
const char *name,
unsigned int flags);
void virLogOutputFree(virLogOutputPtr output);
void virLogOutputListFree(virLogOutputPtr *list, int count);
/*
* Internal logging API