]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: console: check if console was shutdown in callbacks
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Mon, 25 Feb 2019 14:10:01 +0000 (17:10 +0300)
committerNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Thu, 4 Apr 2019 07:36:04 +0000 (10:36 +0300)
On error in main thread virConsoleShutdown is called which
deletes fd watches/stream callback and yet callbacks can
be called after. Thus we can incorrectly allocate
terminalToStream.data memory and get memory leak for example.
Let's check if console was shutdown in the very beginning of
callbacks.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
tools/virsh-console.c

index 3dae70799e2b7a7177821f1040529b422a39fcef..d109734acf97076031bf3c42ba2a2f57bb728dda 100644 (file)
@@ -139,6 +139,10 @@ virConsoleEventOnStream(virStreamPtr st,
 
     virObjectLock(con);
 
+    /* we got late event after console was shutdown */
+    if (!con->st)
+        goto cleanup;
+
     if (events & VIR_STREAM_EVENT_READABLE) {
         size_t avail = con->streamToTerminal.length -
             con->streamToTerminal.offset;
@@ -219,6 +223,10 @@ virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED,
 
     virObjectLock(con);
 
+    /* we got late event after console was shutdown */
+    if (!con->st)
+        goto cleanup;
+
     if (events & VIR_EVENT_HANDLE_READABLE) {
         size_t avail = con->terminalToStream.length -
             con->terminalToStream.offset;
@@ -279,6 +287,10 @@ virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
 
     virObjectLock(con);
 
+    /* we got late event after console was shutdown */
+    if (!con->st)
+        goto cleanup;
+
     if (events & VIR_EVENT_HANDLE_WRITABLE &&
         con->streamToTerminal.offset) {
         ssize_t done;