From 9bc925d0e9325bae533e9515eed59e795491729b Mon Sep 17 00:00:00 2001 From: Jesse Smith Date: Mon, 4 Nov 2019 12:12:44 -0400 Subject: [PATCH] Avoid freeing unused memory. Some code clean-up. Patch provided by David Hoyer. --- doc/Changelog | 2 ++ src/killall5.c | 21 +++++++-------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index aa244d7..24ecba0 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,6 +4,8 @@ sysvinit (2.97) unreleased; urgency=low Added logsave and readbootlog to list of files git ignores. - Patches provided by Petr Ovtchenkov. + * Code clean-up and making sure we avoid freeing unused memory. + Patch provided by David Hoyer. sysvinit (2.96) released; urgency=low diff --git a/src/killall5.c b/src/killall5.c index 8b5cb38..ab05585 100644 --- a/src/killall5.c +++ b/src/killall5.c @@ -513,7 +513,7 @@ int readproc(int do_stat) if (p->argv0) free(p->argv0); if (p->argv1) free(p->argv1); if (p->statname) free(p->statname); - free(p->pathname); + if (p->pathname) free(p->pathname); free(p); } plist = NULL; @@ -562,7 +562,7 @@ int readproc(int do_stat) if (p->argv0) free(p->argv0); if (p->argv1) free(p->argv1); if (p->statname) free(p->statname); - free(p->pathname); + if (p->pathname) free(p->pathname); free(p); continue; } @@ -578,19 +578,12 @@ int readproc(int do_stat) /* Get session, startcode, endcode. */ startcode = endcode = 0; - /* - if (sscanf(q, "%*c %*d %*d %d %*d %*d %*u %*u " + if (sscanf(q, "%10s %*d %*d %d %*d %*d %*u %*u " "%*u %*u %*u %*u %*u %*d %*d " "%*d %*d %*d %*d %*u %*u %*d " "%*u %lu %lu", - &p->sid, &startcode, &endcode) != 3) { - */ - if (sscanf(q, "%10s %*d %*d %d %*d %*d %*u %*u " - "%*u %*u %*u %*u %*u %*d %*d " - "%*d %*d %*d %*d %*u %*u %*d " - "%*u %lu %lu", - process_status, - &p->sid, &startcode, &endcode) != 4) { + process_status, + &p->sid, &startcode, &endcode) != 4) { p->sid = 0; nsyslog(LOG_ERR, "can't read sid from %s\n", @@ -624,7 +617,7 @@ int readproc(int do_stat) if (p->argv0) free(p->argv0); if (p->argv1) free(p->argv1); if (p->statname) free(p->statname); - free(p->pathname); + if (p->pathname) free(p->pathname); free(p); continue; } @@ -672,7 +665,7 @@ int readproc(int do_stat) if (p->argv0) free(p->argv0); if (p->argv1) free(p->argv1); if (p->statname) free(p->statname); - free(p->pathname); + if (p->pathname) free(p->pathname); free(p); continue; }