commit:     fb81028121471c32bbcc88a61956baa7264ff090
Author:     Doug Freed <dwfreed <AT> mtu <DOT> edu>
AuthorDate: Mon Jan 12 15:10:29 2015 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue Jan 13 07:07:02 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=fb810281

fix double free of pidfile

This fixes a double free of the pidfile variable. For discussion of this
issue, see the bug.

X-Gentoo-Bug: 531600
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=531600

---
 src/librc/librc-daemon.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/librc/librc-daemon.c b/src/librc/librc-daemon.c
index 02aff5a..76fdd7b 100644
--- a/src/librc/librc-daemon.c
+++ b/src/librc/librc-daemon.c
@@ -560,22 +560,20 @@ rc_service_daemons_crashed(const char *service)
                        spidfile = xmalloc(strlen(ch_root) + strlen(pidfile) + 
1);
                        strcpy(spidfile, ch_root);
                        strcat(spidfile, pidfile);
+                       free(pidfile);
+                       pidfile = spidfile;
                }
 
                pid = 0;
-               if (spidfile) {
+               if (pidfile) {
                        retval = true;
-                       if ((fp = fopen(spidfile, "r"))) {
+                       if ((fp = fopen(pidfile, "r"))) {
                                if (fscanf(fp, "%d", &pid) == 1)
                                        retval = false;
                                fclose(fp);
                        }
-                       free(spidfile);
-                       spidfile = NULL;
-                       if (ch_root) {
-                               free(pidfile);
-                               pidfile = NULL;
-                       }
+                       free(pidfile);
+                       pidfile = NULL;
 
                        /* We have the pid, so no need to match
                           on exec or name */

Reply via email to