aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-03-17 10:18:27 (GMT)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-03-17 10:18:27 (GMT)
commit387d5cc7dde2d440a836ad2ebec5cd2834526e8c (patch)
treea356b15d3c9b2cf158bf5bab0945ab8661a4a1af
parent22b06353227e04695b1b0a9622b896b948adba89 (diff)
dvbv5-zap: improve program exit code
While testing the program with Valgrind, it would keep reporting about non-freed data. The main reason is that, when called in non-record and non-monitor mode, the while() loop doesn't check for the timeout indication. Solve that and be sure that all strdup() vars will be freed too. On my tests, on normal mode, on monitor mode and on record mode, it now shows no memory leaks with Valgrind. Having zero leaks in Valgrind is important mostly because we don't want the libraries to leak. Having all memory allocated internally at the program freed means that, if Valgrind will report any memory leaks in the future, it would belong to the library code. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
-rw-r--r--utils/dvb/dvbv5-zap.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/utils/dvb/dvbv5-zap.c b/utils/dvb/dvbv5-zap.c
index 95d8d35..06b31a3 100644
--- a/utils/dvb/dvbv5-zap.c
+++ b/utils/dvb/dvbv5-zap.c
@@ -373,6 +373,7 @@ static void do_timeout(int x)
signal(SIGALRM, do_timeout);
} else {
/* something has gone wrong ... exit */
+ fprintf(stderr, "Forcing program stop due to timeout or terminate signal\n");
exit(1);
}
}
@@ -1016,6 +1017,8 @@ static void set_signals(struct arguments *args)
}
}
+const static char *default_dvr_pipe = "/tmp/dvr-pipe";
+
int main(int argc, char **argv)
{
struct arguments args = {};
@@ -1046,11 +1049,10 @@ int main(int argc, char **argv)
textdomain (PACKAGE);
#endif
- memset(&args, 0, sizeof(args));
args.sat_number = -1;
args.lna = LNA_AUTO;
args.input_format = FILE_DVBV5;
- args.dvr_pipe = "/tmp/dvr-pipe";
+ args.dvr_pipe = default_dvr_pipe;
args.low_traffic = 1;
if (argp_parse(&argp, argc, argv, ARGP_NO_HELP | ARGP_NO_EXIT, &idx, &args)) {
@@ -1365,7 +1367,7 @@ int main(int argc, char **argv)
get_show_stats(stderr, &args, parms, 0);
} else {
/* Wait until timeout or being killed */
- while (1) {
+ while (!timeout_flag) {
get_show_stats(stderr, &args, parms, 1);
usleep(1000000);
}
@@ -1373,9 +1375,25 @@ int main(int argc, char **argv)
err = 0;
err:
+ dvb_dev_free(dvb);
+
+ /*
+ * Just to make Valgrind happier. It should be noticed
+ * That, if an error happens or if the program exits via
+ * timeout code at forced mode, it may not free those.
+ */
if (args.confname)
free(args.confname);
- dvb_dev_free(dvb);
+ if (args.filename)
+ free(args.filename);
+ if (args.lnb_name)
+ free(args.lnb_name);
+ if (args.search)
+ free(args.search);
+ if (args.server)
+ free(args.search);
+ if (args.dvr_pipe != default_dvr_pipe)
+ free(args.dvr_pipe);
return err;
}

Privacy Policy