Skip to content

Commit

Permalink
ts_setup: fix possible memory leak
Browse files Browse the repository at this point in the history
Fixes #151
  • Loading branch information
merge committed Apr 29, 2019
1 parent 2abfc27 commit 2be6a0e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/ts_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ static char *scan_devices(void)
struct dirent **namelist;
int i, ndev;
char *filename = NULL;
int have_touchscreen = 0;
long propbit[BITS_TO_LONGS(INPUT_PROP_MAX)] = {0};

#ifdef DEBUG
Expand All @@ -85,30 +84,26 @@ static char *scan_devices(void)
close(fd);
continue;
} else {
have_touchscreen = 1;
}

close(fd);
free(namelist[i]);

if (have_touchscreen) {
close(fd);
filename = malloc(strlen(DEV_INPUT_EVENT) +
strlen(EVENT_DEV_NAME) +
12);
if (!filename)
return NULL;
break;

sprintf(filename, "%s/%s%d",
DEV_INPUT_EVENT, EVENT_DEV_NAME,
i);
break;
}
}

free(namelist);
for (i = 0; i < ndev; ++i)
free(namelist[i]);

return filename;
}
free(namelist);

return NULL;
return filename;
}

#endif /* __linux__ */
Expand Down

0 comments on commit 2be6a0e

Please sign in to comment.