mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
scanner: Close input resource when done to prevent leak
Addresses this error reported by Denis Denisov: [src/scanner.c:1415]: (error) Resource leak: input Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> v2: Also close input for other exit points in main. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: David FORT <contact@hardening-consulting.com>
This commit is contained in:
parent
d20a0b8758
commit
e0b2166c99
1 changed files with 5 additions and 0 deletions
|
|
@ -1531,6 +1531,7 @@ int main(int argc, char *argv[])
|
||||||
if (freopen(argv[2], "w", stdout) == NULL) {
|
if (freopen(argv[2], "w", stdout) == NULL) {
|
||||||
fprintf(stderr, "Could not open output file: %s\n",
|
fprintf(stderr, "Could not open output file: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
fclose(input);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1550,6 +1551,7 @@ int main(int argc, char *argv[])
|
||||||
XML_SetUserData(ctx.parser, &ctx);
|
XML_SetUserData(ctx.parser, &ctx);
|
||||||
if (ctx.parser == NULL) {
|
if (ctx.parser == NULL) {
|
||||||
fprintf(stderr, "failed to create parser\n");
|
fprintf(stderr, "failed to create parser\n");
|
||||||
|
fclose(input);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1561,6 +1563,7 @@ int main(int argc, char *argv[])
|
||||||
len = fread(buf, 1, XML_BUFFER_SIZE, input);
|
len = fread(buf, 1, XML_BUFFER_SIZE, input);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
fprintf(stderr, "fread: %m\n");
|
fprintf(stderr, "fread: %m\n");
|
||||||
|
fclose(input);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
|
if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
|
||||||
|
|
@ -1569,6 +1572,7 @@ int main(int argc, char *argv[])
|
||||||
XML_GetCurrentLineNumber(ctx.parser),
|
XML_GetCurrentLineNumber(ctx.parser),
|
||||||
XML_GetCurrentColumnNumber(ctx.parser),
|
XML_GetCurrentColumnNumber(ctx.parser),
|
||||||
XML_ErrorString(XML_GetErrorCode(ctx.parser)));
|
XML_ErrorString(XML_GetErrorCode(ctx.parser)));
|
||||||
|
fclose(input);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
|
|
@ -1588,6 +1592,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
free_protocol(&protocol);
|
free_protocol(&protocol);
|
||||||
|
fclose(input);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue