]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 201678 via svnmerge from
authorDavid Vossel <dvossel@digium.com>
Thu, 18 Jun 2009 16:51:54 +0000 (16:51 +0000)
committerDavid Vossel <dvossel@digium.com>
Thu, 18 Jun 2009 16:51:54 +0000 (16:51 +0000)
https://origsvn.digium.com/svn/asterisk/trunk

........
  r201678 | dvossel | 2009-06-18 11:37:42 -0500 (Thu, 18 Jun 2009) | 11 lines

  fixes some memory leaks and redundant conditions

  (closes issue #15269)
  Reported by: contactmayankjain
  Patches:
        patch.txt uploaded by contactmayankjain (license 740)
        memory_leak_stuff.trunk.diff uploaded by dvossel (license 671)
  Tested by: contactmayankjain, dvossel
........

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@201680 65c4cc65-6c06-0410-ace0-fbb531ad65f3

15 files changed:
apps/app_rpt.c
channels/h323/ast_h323.cxx
channels/misdn/isdn_lib.c
channels/xpmr/xpmr.c
codecs/gsm/src/gsm_destroy.c
main/ast_expr2.c
main/ast_expr2f.c
main/asterisk.c
pbx/pbx_config.c
res/ael/ael_lex.c
res/res_config_ldap.c
utils/ael_main.c
utils/conf2ael.c
utils/extconf.c
utils/stereorize.c

index 78d0d9cba7f8c8f0685b261592c5283cb5571c60..75e95855980a0fdfa2c9e2e5fc99845a1704b690 100644 (file)
@@ -3940,7 +3940,7 @@ struct  rpt_tele *tlist;
 struct rpt *myrpt;
 struct rpt_link *l,*l1,linkbase;
 struct ast_channel *mychannel;
-int id_malloc, vmajor, vminor, m;
+int vmajor, vminor, m;
 char *p,*ct,*ct_copy,*ident, *nodename,*cp;
 time_t t;
 #ifdef NEW_ASTERISK
@@ -3987,14 +3987,10 @@ struct dahdi_params par;
                        ast_free(mytele);
                        pthread_exit(NULL);
                }
-               else{
-                       id_malloc = 1;
-               }
        }
        else
        {
                ident = "";
-               id_malloc = 0;
        }
        rpt_mutex_unlock(&myrpt->lock);
                
@@ -4010,8 +4006,7 @@ struct dahdi_params par;
                ast_log(LOG_NOTICE,"Telemetry thread aborted at line %d, mode: %d\n",__LINE__, mytele->mode); /*@@@@@@@@@@@*/
                rpt_mutex_unlock(&myrpt->lock);
                ast_free(nodename);
-               if(id_malloc)
-                       ast_free(ident);
+               ast_free(ident);
                ast_free(mytele);               
                pthread_exit(NULL);
        }
@@ -4057,8 +4052,7 @@ struct dahdi_params par;
                rpt_mutex_unlock(&myrpt->lock);
                ast_log(LOG_NOTICE,"Telemetry thread aborted at line %d, mode: %d\n",__LINE__, mytele->mode); /*@@@@@@@@@@@*/
                ast_free(nodename);
-               if(id_malloc)
-                       ast_free(ident);
+               ast_free(ident);
                ast_free(mytele);               
                ast_hangup(mychannel);
                pthread_exit(NULL);
@@ -4252,8 +4246,7 @@ struct dahdi_params par;
                                rpt_mutex_unlock(&myrpt->lock);
                                ast_log(LOG_NOTICE,"Telemetry thread aborted at line %d, mode: %d\n",__LINE__, mytele->mode); /*@@@@@@@@@@@*/
                                ast_free(nodename);
-                               if(id_malloc)
-                                       ast_free(ident);
+                               ast_free(ident);
                                ast_free(mytele);               
                                ast_hangup(mychannel);
                                pthread_exit(NULL);
@@ -4293,8 +4286,7 @@ struct dahdi_params par;
                                rpt_mutex_unlock(&myrpt->lock);
                                ast_log(LOG_NOTICE,"Telemetry thread aborted at line %d, mode: %d\n",__LINE__, mytele->mode); /*@@@@@@@@@@@*/
                                ast_free(nodename);
-                               if(id_malloc)
-                                       ast_free(ident);
+                               ast_free(ident);
                                ast_free(mytele);               
                                ast_hangup(mychannel);
                                pthread_exit(NULL);
@@ -4816,8 +4808,7 @@ struct dahdi_params par;
                                rpt_mutex_unlock(&myrpt->lock);
                                ast_log(LOG_NOTICE,"Telemetry thread aborted at line %d, mode: %d\n",__LINE__, mytele->mode); /*@@@@@@@@@@@*/
                                ast_free(nodename);
-                               if(id_malloc)
-                                       ast_free(ident);
+                               ast_free(ident);
                                ast_free(mytele);               
                                ast_hangup(mychannel);
                                pthread_exit(NULL);
@@ -5193,8 +5184,7 @@ struct dahdi_params par;
        myrpt->active_telem = NULL;
        rpt_mutex_unlock(&myrpt->lock);
        ast_free(nodename);
-       if(id_malloc)
-               ast_free(ident);
+       ast_free(ident);
        ast_free(mytele);               
        ast_hangup(mychannel);
 #ifdef  APP_RPT_LOCK_DEBUG
index cad4c2cfce8b6251d2ab24ec28b82ca4d428dd70..5c35620c01d748254b44509b8115d6e4629a71a2 100644 (file)
@@ -571,8 +571,7 @@ MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned callReference,
 {
 #ifdef H323_H450
        /* Dispatcher will free out all registered handlers */
-       if (h450dispatcher)
-               delete h450dispatcher;
+       delete h450dispatcher;
        h450dispatcher = new H450xDispatcher(*this);
        h4502handler = new H4502Handler(*this, *h450dispatcher);
        h4504handler = new MyH4504Handler(*this, *h450dispatcher);
@@ -1987,8 +1986,9 @@ void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, in
        if (cap && cap->IsUsable(*this)) {
                lastcap++;
                lastcap = localCapabilities.SetCapability(0, lastcap, cap);
-       } else if (cap)
+       } else {
                delete cap;                             /* Capability is not usable */
+       }
 
        dtmfMode = dtmf_mode;
        if (h323debug) {
@@ -2000,8 +2000,9 @@ void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, in
                        cap = new H323_UserInputCapability(H323_UserInputCapability::BasicString);
                        if (cap && cap->IsUsable(*this)) {
                                lastcap = localCapabilities.SetCapability(0, lastcap, cap);
-                       } else if (cap)
+                       } else {
                                delete cap;             /* Capability is not usable */
+                       }       
                        sendUserInputMode = SendUserInputAsString;
                } else {
                        if ((dtmfMode & H323_DTMF_RFC2833) != 0) {
@@ -2010,8 +2011,7 @@ void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, in
                                        lastcap = localCapabilities.SetCapability(0, lastcap, cap);
                                else {
                                        dtmfMode |= H323_DTMF_SIGNAL;
-                                       if (cap)
-                                               delete cap;     /* Capability is not usable */
+                                       delete cap;     /* Capability is not usable */
                                }
                        }
                        if ((dtmfMode & H323_DTMF_CISCO) != 0) {
@@ -2023,8 +2023,7 @@ void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, in
                                        dtmfMode |= H323_DTMF_SIGNAL;
                                } else {
                                        dtmfMode |= H323_DTMF_SIGNAL;
-                                       if (cap)
-                                               delete cap;     /* Capability is not usable */
+                                       delete cap;     /* Capability is not usable */
                                }
                        }
                        if ((dtmfMode & H323_DTMF_SIGNAL) != 0) {
@@ -2032,7 +2031,7 @@ void MyH323Connection::SetCapabilities(int caps, int dtmf_mode, void *_prefs, in
                                cap = new H323_UserInputCapability(H323_UserInputCapability::SignalToneH245);
                                if (cap && cap->IsUsable(*this))
                                        lastcap = localCapabilities.SetCapability(0, lastcap, cap);
-                               else if (cap)
+                               else
                                        delete cap;     /* Capability is not usable */
                        }
                        sendUserInputMode = SendUserInputAsTone;        /* RFC2833 transmission handled at Asterisk level */
index 2942ecfbb91be0da081799223ca06823d11241e5..c630bc8da54ce541cdcdab099775671c84eff184 100644 (file)
@@ -2231,6 +2231,10 @@ static void misdn_save_data(int id, char *p1, int l1, char *p2, int l2)
 
        if (!rx || !tx) {
                cb_log(0,0,"Couldn't open files: %s\n",strerror(errno));
+               if (rx)
+                       fclose(rx);
+               if (tx)
+                       fclose(tx);
                return ;
        }
        
index c2742cbc383a1d06172b970ac23c43d5f54ccd2d..7c87410b23857bf04ae01efa028792b5e61a58a6 100755 (executable)
@@ -157,7 +157,7 @@ i16 string_parse(char *src, char **dest, char ***ptrs)
        TRACEJ(2,(" source len = %i\n",slen));
 
        pd=*dest;
-       if(pd) free(pd);
+       free(pd);
     pd=calloc(slen+1,1);
        memcpy(pd,src,slen);
        *dest=pd;
index 4807c0acdda2442411619418bc76671afce875ac..b2748fc97436526f5495b6be1b51fe96b295b486 100644 (file)
@@ -22,5 +22,5 @@
 
 void gsm_destroy P1((S), gsm S)
 {
-       if (S) free((char *)S);
+       free((char *)S);
 }
index 44b0b7ece87e8f3d7c1ce4b8f2a6bb306c1c1be0..068e47acd06427e78bca8a4bf9ce9f79d2eb4cde 100644 (file)
@@ -2415,6 +2415,7 @@ static void
 free_value (struct val *vp)
 {      
        if (vp==NULL) {
+               free(vp);
                return;
        }
        if (vp->type == AST_EXPR_string || vp->type == AST_EXPR_numeric_string)
index 528afd9ae60e2673a62c8d0ca72a34d55b9bb073..91793b6308f03cfbfa22f014de63d9a95e2b893a 100644 (file)
@@ -2379,7 +2379,7 @@ int ast_yyerror(const char *, YYLTYPE *, struct parse_io *); /* likewise */
 
 void ast_yyfree(void *ptr, yyscan_t yyscanner)
 {
-      if (ptr) /* the normal generated ast_yyfree func just frees its first arg;
+       /* the normal generated ast_yyfree func just frees its first arg;
                     this get complaints on some systems, as sometimes this
                     arg is a nil ptr! It's usually not fatal, but is irritating! */
               free( (char *) ptr );
@@ -2423,8 +2423,7 @@ int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
                        else
                                buf[0] = 0;
                        return_value = strlen(buf);
-                       if (io.val->u.s)
-                               free(io.val->u.s);
+                       free(io.val->u.s);
                }
                free(io.val);
        }
index 42e091ede5d106c6c5798f50a1cec2f8cd1c2326..1ae468ceca43181f794b6e1516ccec81e8d3cfd0 100644 (file)
@@ -802,8 +802,7 @@ void ast_unregister_atexit(void (*func)(void))
        AST_RWLIST_TRAVERSE_SAFE_END;
        AST_RWLIST_UNLOCK(&atexits);
 
-       if (ae)
-               free(ae);
+       free(ae);
 }
 
 /* Sending commands from consoles back to the daemon requires a terminating NULL */
index 373acc4bd37e53dab373a206621b1f8e0f109ea8..e3382a2f13a7ca34b390e74ff7d36f1ba0693b42 100644 (file)
@@ -451,8 +451,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
 
                ast_unlock_contexts();
        error2:
-               if (exten)
-                       free(exten);
+               free(exten);
        } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
                char *exten = NULL, *context, *cid, *p;
                struct ast_context *c;
@@ -509,8 +508,7 @@ static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
                }
                ast_unlock_contexts();
        error3:
-               if (exten)
-                       free(exten);
+               free(exten);
        }
        return ret; 
 }
@@ -1139,8 +1137,7 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
                                ret = strdup(ast_get_context_name(c));
                }
 
-               if (ignorepat)
-                       free(ignorepat);
+               free(ignorepat);
                ast_unlock_contexts();
                return ret;
        }
index 4e792aefe1647d762a92a1b7321dda1e457cc284..6517644bde7a6f399c1ac7daa5445e48454c0596 100644 (file)
@@ -3221,8 +3221,7 @@ static void pbcpush(char x)
 
 void ael_yyfree(void *ptr, yyscan_t yyscanner)
 {
-       if (ptr)
-               free( (char*) ptr );
+       free( (char*) ptr );
 }
 
 static int pbcpop(char x)
@@ -3361,8 +3360,7 @@ struct pval *ael2_parse(char *filename, int *errors)
                *errors = 1;
                return 0;
        }
-       if (my_file)
-               free(my_file);
+       free(my_file);
        my_file = strdup(filename);
        stat(filename, &stats);
        buffer = (char*)malloc(stats.st_size+2);
index 04066074d1b29f80469d7e61d3ec25d16e220112..441ae365423046178cd150df67f5d78f66b89367 100644 (file)
@@ -871,12 +871,8 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
                }
        }
 
-       if (filter)
-               ast_free(filter);
-
-       if (clean_basedn)
-               ast_free(clean_basedn);
-
+       ast_free(filter);
+       ast_free(clean_basedn);
        ast_mutex_unlock(&ldap_lock);
 
        return vars;
@@ -1270,10 +1266,8 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
                        ldap_err2string(result));
 
                ast_mutex_unlock(&ldap_lock);
-               if (filter)
-                       free(filter);
-               if (clean_basedn)
-                       free(clean_basedn);
+               free(filter);
+               free(clean_basedn);
                ldap_msgfree(ldap_result_msg);
                ldap_mods_free(ldap_mods, 0);
                return -1;
@@ -1296,10 +1290,8 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
        }
 
        ast_mutex_unlock(&ldap_lock);
-       if (filter)
-               free(filter);
-       if (clean_basedn)
-               free(clean_basedn);
+       free(filter);
+       free(clean_basedn);
        ldap_msgfree(ldap_result_msg);
        ldap_mods_free(ldap_mods, 0);
        return num_entries;
index ba7970955d8751751e7d155685ea1f6ccf641596..9249cd77b3aa30ec0cf2d6464095de6cb8619720 100644 (file)
@@ -299,8 +299,7 @@ int ast_add_extension2(struct ast_context *con,
        }
        
        /* since add_extension2 is responsible for the malloc'd data stuff */
-       if( data )
-               free(data);
+       free(data);
        return 0;
 }
 
index e0711808ba36271626111a9a21766fdd78efa2a8..3b15336c318e31fcd1431052cf3d2b7b8dd813e2 100644 (file)
@@ -471,7 +471,7 @@ int main(int argc, char **argv)
                                                                if (mon) {
                                                                        *mon++ = 0;
                                                                        /* now all 4 fields are set; what do we do? */
-                                                                       pvalIncludesAddIncludeWithTimeConstraints(incl, all, hr, dow, dom, mon);
+                                                                       pvalIncludesAddIncludeWithTimeConstraints(incl, strdup(all), strdup(hr), strdup(dow), strdup(dom), strdup(mon));
                                                                        /* the original data is always best to keep (no 2-min rounding) */
                                                                } else {
                                                                        ast_log(LOG_ERROR,"No month spec attached to include!\n");
@@ -483,6 +483,7 @@ int main(int argc, char **argv)
                                                        ast_log(LOG_ERROR,"No day of week spec attached to include!\n");
                                                }
                                        }
+                                       free(all);
                                }
                                tmpi = tmpi->next;
                        }
index ebb2220a0089905360069f83b655cdd95c35407e..7f2d68196b819e900155dd13c35a34c88bde2790 100644 (file)
@@ -2993,8 +2993,7 @@ static struct ast_var_t *ast_var_assign(const char *name, const char *value)
        
 static void ast_var_delete(struct ast_var_t *var)
 {
-       if (var)
-               free(var);
+       free(var);
 }
 
 
index c8428320d673b122ffd727e2f69453117a9f9526..31f1b1fbed1ad8275ebb507673eead7834c33e68 100644 (file)
@@ -156,4 +156,7 @@ int main( int argcount, char *args[])
       }
    }
    /* That was an endless loop. This point is never reached. */
+   free(leftsample);
+   free(rightsample);
+   free(stereosample);
 }