Actually perform the swap between the active set of outputs and the
user-provided copy. Deallocation ensures that no file descriptors that should
not have been closed are not closed and all descriptors that should be closed
are closed properly.
---
src/util/virlog.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/util/virlog.c b/src/util/virlog.c
index a20cde4..8e14a9e 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1641,22 +1641,29 @@ virLogSetOutputs(const char *outputs)
* @outputs: new set of outputs to be defined
* @noutputs: number of outputs in @outputs
*
- * Resets any existing set of outputs and defines a completely new one.
+ * Swaps any existing set of outputs with a completely new one.
*
* Returns number of outputs successfully defined or -1 in case of error;
*/
int
virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
{
+ size_t count;
+ virLogOutputPtr *tmp = NULL;
+
if (virLogInitialize() < 0)
return -1;
virLogLock();
- virLogResetOutputs();
+ /* swap the currently defined list with a new copy and */
+ tmp = virLogOutputs;
+ count = virLogNbOutputs;
virLogOutputs = outputs;
virLogNbOutputs = noutputs;
virLogUnlock();
+ virLogOutputListFree(tmp, count);
+
return virLogNbOutputs;
}
--
2.4.11