提交 218f866f 编写于 作者: J Jim Meyering

Avoid segfault upon malloc failure, and plug a leak.

* src/test.c (testDomainSave): Detect testDomainDumpXML failure.  Free "xml".
上级 5561e912
Wed Jan 30 20:49:34 CET 2008 Jim Meyering <meyering@redhat.com>
Avoid segfault upon malloc failure, and plug a leak.
* src/test.c (testDomainSave): Detect testDomainDumpXML failure.
Free "xml".
Plug test-related leaks.
* src/test.c (testLoadNetwork): Free forwardDev.
(testLoadDomain): Free ctxt.
......
/*
* test.c: A "mock" hypervisor for use by application unit tests
*
* Copyright (C) 2006-2007 Red Hat, Inc.
* Copyright (C) 2006-2008 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
......@@ -1281,6 +1281,11 @@ static int testDomainSave(virDomainPtr domain,
GET_DOMAIN(domain, -1);
xml = testDomainDumpXML(domain, 0);
if (xml == NULL) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot allocate space for metadata");
return (-1);
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
......@@ -1303,9 +1308,11 @@ static int testDomainSave(virDomainPtr domain,
if (write(fd, xml, len) != len) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot write metadata");
free(xml);
close(fd);
return (-1);
}
free(xml);
if (close(fd) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
"cannot save domain data");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册