Author: pjd
Date: Sun Oct 24 15:41:23 2010
New Revision: 214274
URL: http://svn.freebsd.org/changeset/base/214274

Log:
  Plug memory leaks.
  
  Found with:   valgrind
  MFC after:    3 days

Modified:
  head/sbin/hastd/parse.y
  head/sbin/hastd/primary.c
  head/sbin/hastd/synch.h

Modified: head/sbin/hastd/parse.y
==============================================================================
--- head/sbin/hastd/parse.y     Sun Oct 24 15:38:58 2010        (r214273)
+++ head/sbin/hastd/parse.y     Sun Oct 24 15:41:23 2010        (r214274)
@@ -264,6 +264,7 @@ control_statement:  CONTROL STR
                            sizeof(depth0_control)) >=
                            sizeof(depth0_control)) {
                                pjdlog_error("control argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
@@ -274,12 +275,14 @@ control_statement:        CONTROL STR
                            sizeof(lconfig->hc_controladdr)) >=
                            sizeof(lconfig->hc_controladdr)) {
                                pjdlog_error("control argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
                default:
                        assert(!"control at wrong depth level");
                }
+               free($2);
        }
        ;
 
@@ -291,6 +294,7 @@ listen_statement:   LISTEN STR
                            sizeof(depth0_listen)) >=
                            sizeof(depth0_listen)) {
                                pjdlog_error("listen argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
@@ -301,12 +305,14 @@ listen_statement: LISTEN STR
                            sizeof(lconfig->hc_listenaddr)) >=
                            sizeof(lconfig->hc_listenaddr)) {
                                pjdlog_error("listen argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
                default:
                        assert(!"listen at wrong depth level");
                }
+               free($2);
        }
        ;
 
@@ -357,6 +363,7 @@ exec_statement:             EXEC STR
                        if (strlcpy(depth0_exec, $2, sizeof(depth0_exec)) >=
                            sizeof(depth0_exec)) {
                                pjdlog_error("Exec path is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
@@ -367,12 +374,14 @@ exec_statement:           EXEC STR
                            sizeof(curres->hr_exec)) >=
                            sizeof(curres->hr_exec)) {
                                pjdlog_error("Exec path is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
                default:
                        assert(!"exec at wrong depth level");
                }
+               free($2);
        }
        ;
 
@@ -386,6 +395,7 @@ node_start: STR
        {
                switch (isitme($1)) {
                case -1:
+                       free($1);
                        return (1);
                case 0:
                        break;
@@ -395,6 +405,7 @@ node_start: STR
                default:
                        assert(!"invalid isitme() return value");
                }
+               free($1);
        }
        ;
 
@@ -482,14 +493,17 @@ resource_start:   STR
                curres = calloc(1, sizeof(*curres));
                if (curres == NULL) {
                        pjdlog_error("Unable to allocate memory for resource.");
+                       free($1);
                        return (1);
                }
                if (strlcpy(curres->hr_name, $1,
                    sizeof(curres->hr_name)) >=
                    sizeof(curres->hr_name)) {
                        pjdlog_error("Resource name is too long.");
+                       free($1);
                        return (1);
                }
+               free($1);
                curres->hr_role = HAST_ROLE_INIT;
                curres->hr_previous_role = HAST_ROLE_INIT;
                curres->hr_replication = -1;
@@ -530,6 +544,7 @@ name_statement:             NAME STR
                            sizeof(depth1_provname)) >=
                            sizeof(depth1_provname)) {
                                pjdlog_error("name argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
@@ -541,12 +556,14 @@ name_statement:           NAME STR
                            sizeof(curres->hr_provname)) >=
                            sizeof(curres->hr_provname)) {
                                pjdlog_error("name argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
                default:
                        assert(!"name at wrong depth level");
                }
+               free($2);
        }
        ;
 
@@ -558,6 +575,7 @@ local_statement:    LOCAL STR
                            sizeof(depth1_localpath)) >=
                            sizeof(depth1_localpath)) {
                                pjdlog_error("local argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
@@ -569,12 +587,14 @@ local_statement:  LOCAL STR
                            sizeof(curres->hr_localpath)) >=
                            sizeof(curres->hr_localpath)) {
                                pjdlog_error("local argument is too long.");
+                               free($2);
                                return (1);
                        }
                        break;
                default:
                        assert(!"local at wrong depth level");
                }
+               free($2);
        }
        ;
 
@@ -589,6 +609,7 @@ resource_node_start:        STR
                if (curres != NULL) {
                        switch (isitme($1)) {
                        case -1:
+                               free($1);
                                return (1);
                        case 0:
                                break;
@@ -599,6 +620,7 @@ resource_node_start:        STR
                                assert(!"invalid isitme() return value");
                        }
                }
+               free($1);
        }
        ;
 
@@ -624,8 +646,10 @@ remote_statement:  REMOTE STR
                            sizeof(curres->hr_remoteaddr)) >=
                            sizeof(curres->hr_remoteaddr)) {
                                pjdlog_error("remote argument is too long.");
+                               free($2);
                                return (1);
                        }
                }
+               free($2);
        }
        ;

Modified: head/sbin/hastd/primary.c
==============================================================================
--- head/sbin/hastd/primary.c   Sun Oct 24 15:38:58 2010        (r214273)
+++ head/sbin/hastd/primary.c   Sun Oct 24 15:41:23 2010        (r214274)
@@ -646,6 +646,7 @@ init_remote(struct hast_resource *res, s
                 */
                (void)hast_activemap_flush(res);
        }
+       nv_free(nvin);
        pjdlog_info("Connected to %s.", res->hr_remoteaddr);
        if (inp != NULL && outp != NULL) {
                *inp = in;

Modified: head/sbin/hastd/synch.h
==============================================================================
--- head/sbin/hastd/synch.h     Sun Oct 24 15:38:58 2010        (r214273)
+++ head/sbin/hastd/synch.h     Sun Oct 24 15:41:23 2010        (r214274)
@@ -140,6 +140,8 @@ cv_init(pthread_cond_t *cv)
        assert(error == 0);
        error = pthread_cond_init(cv, &attr);
        assert(error == 0);
+       error = pthread_condattr_destroy(&attr);
+       assert(error == 0);
 }
 static __inline void
 cv_wait(pthread_cond_t *cv, pthread_mutex_t *lock)
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to