Skip to content

Commit a26487c

Browse files
seeddsclaude
authored andcommitted
host/input: t_controls closes the first temporary file when the second cannot open
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 8208099 commit a26487c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎dm/host/tests/t_controls.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ int main(void) {
4444
char g[] = "/tmp/t_controls_gXXXXXX", p[] = "/tmp/t_controls_pXXXXXX";
4545
int fg = mkstemp(g), fp = mkstemp(p);
4646
FILE *fgf = fg >= 0 ? fdopen(fg, "w") : NULL, *fpf = fp >= 0 ? fdopen(fp, "w") : NULL;
47-
if (!fgf || !fpf) { fprintf(stderr, "t_controls: cannot write the temporary controls files\n"); return 1; }
47+
if (!fgf || !fpf) {
48+
if (fgf) fclose(fgf);
49+
if (fpf) fclose(fpf);
50+
fprintf(stderr, "t_controls: cannot write the temporary controls files\n");
51+
return 1;
52+
}
4853
fputs("pad A=B\nkey 38=X\nmouse=right\nbogus line\n", fgf); fclose(fgf);
4954
fputs("key 38=Y\r\nmouse_speed=3\n", fpf); fclose(fpf);
5055
ctl_defaults(&c); nbad = 0;

0 commit comments

Comments
 (0)