commandtest: Resolve some coverity resource leaks

This commit is contained in:
John Ferlan 2013-01-14 10:35:45 -05:00
parent e2f1fc5220
commit 11a1181260

View File

@ -680,7 +680,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
goto cleanup; goto cleanup;
} }
if (!outbuf || *outbuf) { if (*outbuf) {
puts("output buffer is not an allocated empty string"); puts("output buffer is not an allocated empty string");
goto cleanup; goto cleanup;
} }
@ -702,7 +702,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED)
goto cleanup; goto cleanup;
} }
if (!outbuf || *outbuf || !errbuf || *errbuf) { if (*outbuf || *errbuf) {
puts("output buffers are not allocated empty strings"); puts("output buffers are not allocated empty strings");
goto cleanup; goto cleanup;
} }
@ -936,6 +936,7 @@ mymain(void)
int fd; int fd;
virCommandTestDataPtr test = NULL; virCommandTestDataPtr test = NULL;
int timer = -1; int timer = -1;
int virinitret;
if (virThreadInitialize() < 0) if (virThreadInitialize() < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
@ -963,18 +964,21 @@ mymain(void)
dup2(fd, 6) < 0 || dup2(fd, 6) < 0 ||
dup2(fd, 7) < 0 || dup2(fd, 7) < 0 ||
dup2(fd, 8) < 0 || dup2(fd, 8) < 0 ||
(fd > 8 && VIR_CLOSE(fd) < 0)) (fd > 8 && VIR_CLOSE(fd) < 0)) {
VIR_FORCE_CLOSE(fd);
return EXIT_FAILURE; return EXIT_FAILURE;
}
/* Prime the debug/verbose settings from the env vars, /* Prime the debug/verbose settings from the env vars,
* since we're about to reset 'environ' */ * since we're about to reset 'environ' */
ignore_value(virTestGetDebug()); ignore_value(virTestGetDebug());
ignore_value(virTestGetVerbose()); ignore_value(virTestGetVerbose());
if (virInitialize() < 0) /* Make sure to not leak fd's */
return EXIT_FAILURE; virinitret = virInitialize();
/* Phase two of killing interfering fds; see above. */ /* Phase two of killing interfering fds; see above. */
/* coverity[overwrite_var] - silence the obvious */
fd = 3; fd = 3;
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
fd = 4; fd = 4;
@ -988,6 +992,9 @@ mymain(void)
fd = 8; fd = 8;
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
if (virinitret < 0)
return EXIT_FAILURE;
virEventRegisterDefaultImpl(); virEventRegisterDefaultImpl();
if (VIR_ALLOC(test) < 0) { if (VIR_ALLOC(test) < 0) {
virReportOOMError(); virReportOOMError();