test: log: log_api: Close open fds on error paths

Reported-by: Coverity CID=279091
Signed-off-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Umang Jain 2020-05-15 12:42:53 +00:00 committed by Kieran Bingham
parent 5bb6607933
commit 3706b716eb

View file

@ -87,6 +87,7 @@ protected:
if (logSetFile(path) < 0) { if (logSetFile(path) < 0) {
cerr << "Failed to set log file" << endl; cerr << "Failed to set log file" << endl;
close(fd);
return TestFail; return TestFail;
} }
@ -97,6 +98,7 @@ protected:
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
if (read(fd, buf, sizeof(buf)) < 0) { if (read(fd, buf, sizeof(buf)) < 0) {
cerr << "Failed to read tmp log file" << endl; cerr << "Failed to read tmp log file" << endl;
close(fd);
return TestFail; return TestFail;
} }
close(fd); close(fd);