Skip to content
Snippets Groups Projects
  • Daniel Xu's avatar
    d6f67b83
    qga: Fix memory leak when output stream is unused · d6f67b83
    Daniel Xu authored
    
    If capture-output is requested but one of the channels goes unused (eg.
    we attempt to capture stderr but the command never writes to stderr), we
    can leak memory.
    
    guest_exec_output_watch() is (from what I understand) unconditionally
    called for both streams if output capture is requested. The first call
    will always pass the `p->size == p->length` check b/c both values are
    0. Then GUEST_EXEC_IO_SIZE bytes will be allocated for the stream.
    
    But when we reap the exited process there's a `gei->err.length > 0`
    check to actually free the buffer. Which does not get run if the command
    doesn't write to the stream.
    
    Fix by making free() unconditional.
    
    Reviewed-by: default avatarKonstantin Kostiuk <kkostiuk@redhat.com>
    Signed-off-by: default avatarDaniel Xu <dxu@dxuuu.xyz>
    Signed-off-by: default avatarKonstantin Kostiuk <kkostiuk@redhat.com>
    d6f67b83
    History
    qga: Fix memory leak when output stream is unused
    Daniel Xu authored
    
    If capture-output is requested but one of the channels goes unused (eg.
    we attempt to capture stderr but the command never writes to stderr), we
    can leak memory.
    
    guest_exec_output_watch() is (from what I understand) unconditionally
    called for both streams if output capture is requested. The first call
    will always pass the `p->size == p->length` check b/c both values are
    0. Then GUEST_EXEC_IO_SIZE bytes will be allocated for the stream.
    
    But when we reap the exited process there's a `gei->err.length > 0`
    check to actually free the buffer. Which does not get run if the command
    doesn't write to the stream.
    
    Fix by making free() unconditional.
    
    Reviewed-by: default avatarKonstantin Kostiuk <kkostiuk@redhat.com>
    Signed-off-by: default avatarDaniel Xu <dxu@dxuuu.xyz>
    Signed-off-by: default avatarKonstantin Kostiuk <kkostiuk@redhat.com>