srf02: fix resource leak (unclosed fd)

This commit is contained in:
Beat Küng 2018-06-13 12:10:52 +02:00 committed by Lorenz Meier
parent ab94bf1d60
commit 5cc450c7cb

View File

@ -700,7 +700,7 @@ void info();
void
start(uint8_t rotation)
{
int fd;
int fd = -1;
if (g_dev != nullptr) {
errx(1, "already started");
@ -728,10 +728,15 @@ start(uint8_t rotation)
goto fail;
}
close(fd);
exit(0);
fail:
if (fd >= 0) {
close(fd);
}
if (g_dev != nullptr) {
delete g_dev;
g_dev = nullptr;