From: Andrew Cooper Subject: [PATCH 21/32] qemu-char: fix memory leak in qemu_char_open_pty() Date: Wed, 22 Apr 2015 16:07:58 +0100 Message-ID: <1429715289-4954-21-git-send-email-andrew.cooper3@citrix.com> References: <1429715235-4759-1-git-send-email-andrew.cooper3@citrix.com> <1429715289-4954-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1429715289-4954-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel List-Id: xen-devel@lists.xenproject.org From: Kaifeng Zhu The momery pointed by s and chr could be leaked if openpty return a value less then 0. Signed-off-by: Kaifeng Zhu Coverity-IDs: 1055926 1055927 Reviewed-by: Andrew Cooper --- qemu-char.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qemu-char.c b/qemu-char.c index 324ed16..f62a6af 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -932,6 +932,8 @@ static CharDriverState *qemu_chr_open_pty(void) s = qemu_mallocz(sizeof(PtyCharDriver)); if (openpty(&s->fd, &slave_fd, pty_name, NULL, NULL) < 0) { + qemu_free(s); + qemu_free(chr); return NULL; } -- 1.7.10.4