[PATCH wayland v2] scanner: Close input resource when done to prevent leak
Jonas Ådahl
jadahl at gmail.com
Thu Oct 1 18:57:25 PDT 2015
On Thu, Oct 01, 2015 at 06:13:29PM -0700, Bryce Harrington wrote:
> Addresses this error reported by Denis Denisov:
>
> [src/scanner.c:1415]: (error) Resource leak: input
>
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
>
> v2: Also close input for other exit points in main.
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
I guess we should also free_protocol() on some of the EXIT_FAILUREs, but
thats not really related to this patch. So..
Reviewed-by: Jonas Ådahl <jadahl at gmail.com>
Jonas
> ---
> src/scanner.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/src/scanner.c b/src/scanner.c
> index 9b41ae4..5504fce 100644
> --- a/src/scanner.c
> +++ b/src/scanner.c
> @@ -1531,6 +1531,7 @@ int main(int argc, char *argv[])
> if (freopen(argv[2], "w", stdout) == NULL) {
> fprintf(stderr, "Could not open output file: %s\n",
> strerror(errno));
> + fclose(input);
> exit(EXIT_FAILURE);
> }
> }
> @@ -1550,6 +1551,7 @@ int main(int argc, char *argv[])
> XML_SetUserData(ctx.parser, &ctx);
> if (ctx.parser == NULL) {
> fprintf(stderr, "failed to create parser\n");
> + fclose(input);
> exit(EXIT_FAILURE);
> }
>
> @@ -1561,6 +1563,7 @@ int main(int argc, char *argv[])
> len = fread(buf, 1, XML_BUFFER_SIZE, input);
> if (len < 0) {
> fprintf(stderr, "fread: %m\n");
> + fclose(input);
> exit(EXIT_FAILURE);
> }
> if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
> @@ -1569,6 +1572,7 @@ int main(int argc, char *argv[])
> XML_GetCurrentLineNumber(ctx.parser),
> XML_GetCurrentColumnNumber(ctx.parser),
> XML_ErrorString(XML_GetErrorCode(ctx.parser)));
> + fclose(input);
> exit(EXIT_FAILURE);
> }
> } while (len > 0);
> @@ -1588,6 +1592,7 @@ int main(int argc, char *argv[])
> }
>
> free_protocol(&protocol);
> + fclose(input);
>
> return 0;
> }
> --
> 1.9.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list