Merged revisions 53358 via svnmerge from
authorJoshua Colp <jcolp@digium.com>
Wed, 7 Feb 2007 15:46:30 +0000 (15:46 +0000)
committerJoshua Colp <jcolp@digium.com>
Wed, 7 Feb 2007 15:46:30 +0000 (15:46 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

................
r53358 | file | 2007-02-07 10:43:39 -0500 (Wed, 07 Feb 2007) | 10 lines

Merged revisions 53357 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r53357 | file | 2007-02-07 10:38:48 -0500 (Wed, 07 Feb 2007) | 2 lines

Fix a few potential memory leaks with realtime users and peers. (issue #8999 reported by bsmithurst)

........

................

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

channels/chan_iax2.c

index f9a4d3f..484e89d 100644 (file)
@@ -2540,8 +2540,10 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
 
        peer = build_peer(peername, var, NULL, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
        
-       if (!peer)
+       if (!peer) {
+               ast_variables_destroy(var);
                return NULL;
+       }
 
        for (tmp = var; tmp; tmp = tmp->next) {
                /* Make sure it's not a user only... */
@@ -2564,11 +2566,12 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
                                dynamic = 1;
                }
        }
-       if (!peer)
-               return NULL;
 
        ast_variables_destroy(var);
 
+       if (!peer)
+               return NULL;
+
        if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
                ast_copy_flags(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
                if (ast_test_flag(peer, IAX_RTAUTOCLEAR)) {
@@ -2627,11 +2630,12 @@ static struct iax2_user *realtime_user(const char *username)
        }
 
        user = build_user(username, var, NULL, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
-       if (!user)
-               return NULL;
 
        ast_variables_destroy(var);
 
+       if (!user)
+               return NULL;
+
        if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
                ast_set_flag(user, IAX_RTCACHEFRIENDS);
                AST_LIST_LOCK(&users);
@@ -4855,16 +4859,14 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                                *key = '\0';
                                key++;
                        }
-                       if (!key || ast_db_get(family, key, buf, sizeof(buf))) {
+                       if (!key || ast_db_get(family, key, buf, sizeof(buf)))
                                ast_log(LOG_WARNING, "Unable to retrieve database password for family/key '%s'!\n", user->dbsecret);
-                               if (ast_test_flag(user, IAX_TEMPONLY)) {
-                                       destroy_user(user);
-                                       user = NULL;
-                               }
-                       } else
+                       else
                                ast_string_field_set(iaxs[callno], secret, buf);
                } else
                        ast_string_field_set(iaxs[callno], secret, user->secret);
+               if (ast_test_flag(user, IAX_TEMPONLY))
+                       destroy_user(user);
                res = 0;
        }
        ast_set2_flag(iaxs[callno], iax2_getpeertrunk(*sin), IAX_TRUNK);