diff --git a/src/conf/virconsole.c b/src/conf/virconsole.c index e665149470c65147ae4c4182a4df90eb3cc7d94d..01f1c84d7427785f29b281bfe2f1035668d8aeb7 100644 --- a/src/conf/virconsole.c +++ b/src/conf/virconsole.c @@ -222,9 +222,6 @@ static void virConsoleHashEntryFree(void *data, const char *pty = name; virStreamPtr st = data; - /* remove callback from stream */ - virFDStreamSetInternalCloseCb(st, NULL, NULL, NULL); - /* free stream reference */ virStreamFree(st); @@ -292,6 +289,18 @@ error: return NULL; } +/** + * Helper to clear stream callbacks when freeing the hash + */ +static void virConsoleFreeClearCallbacks(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *data ATTRIBUTE_UNUSED) +{ + virStreamPtr st = payload; + + virFDStreamSetInternalCloseCb(st, NULL, NULL, NULL); +} + /** * Free structures for handling open console streams. * @@ -303,6 +312,7 @@ void virConsoleFree(virConsolesPtr cons) return; virMutexLock(&cons->lock); + virHashForEach(cons->hash, virConsoleFreeClearCallbacks, NULL); virHashFree(cons->hash); virMutexUnlock(&cons->lock); virMutexDestroy(&cons->lock);