[glib] win_iconv: Fix some file handler leaks on exit
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] win_iconv: Fix some file handler leaks on exit
- Date: Sat, 13 Aug 2016 08:39:20 +0000 (UTC)
commit 5707c91a56fbf436d727dd700426296cd651aeaf
Author: Philip Withnall <philip withnall collabora co uk>
Date: Sat Aug 13 10:31:26 2016 +0200
win_iconv: Fix some file handler leaks on exit
I realise this is a contradiction in terms, but it keeps code analysis
tools happy. As spotted by cppcheck, which could not attend GUADEC, but
sends everyone its best wishes anyway.
glib/win_iconv.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/glib/win_iconv.c b/glib/win_iconv.c
index 63023ca..605e5f0 100644
--- a/glib/win_iconv.c
+++ b/glib/win_iconv.c
@@ -1989,6 +1989,7 @@ main(int argc, char **argv)
size_t r;
FILE *in = stdin;
FILE *out = stdout;
+ FILE *in_allocated = NULL, *out_allocated = NULL;
int ignore = 0;
char *p;
@@ -2012,7 +2013,7 @@ main(int argc, char **argv)
ignore = 1;
else if (strcmp(argv[i], "--output") == 0)
{
- out = fopen(argv[++i], "wb");
+ out_allocated = out = fopen(argv[++i], "wb");
if(out == NULL)
{
fprintf(stderr, "cannot open %s\n", argv[i]);
@@ -2021,7 +2022,7 @@ main(int argc, char **argv)
}
else
{
- in = fopen(argv[i], "rb");
+ in_allocated = in = fopen(argv[i], "rb");
if (in == NULL)
{
fprintf(stderr, "cannot open %s\n", argv[i]);
@@ -2086,6 +2087,11 @@ main(int argc, char **argv)
iconv_close(cd);
+ if (in_allocated != NULL)
+ fclose (in_allocated);
+ if (out_allocated != NULL)
+ fclose (out_allocated);
+
return 0;
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]