]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
chan_sip: fix broken realtime peer count, fix memory leak
authorRussell Bryant <russell@russellbryant.com>
Thu, 5 May 2011 18:20:29 +0000 (18:20 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 5 May 2011 18:20:29 +0000 (18:20 +0000)
This patch addresses two bugs in chan_sip:

1) The count of realtime peers and users was off.  The increment checked the
value of the caching option, while the decrement did not.

2) Add a missing regfree() for a regex.

(closes issue #19108)
Reported by: vrban
Patches:
      missing_regfree.patch uploaded by vrban (license 756)
      sip_object_counter.patch uploaded by vrban (license 756)

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

channels/chan_sip.c

index 3843ce54ab1284ba0aaa76f77620bdc6645c3d7c..9951c56cdf5aa75e2444f404e38dac9a0ca37f03 100644 (file)
@@ -2770,7 +2770,7 @@ static void sip_destroy_peer(struct sip_peer *peer)
        ast_free_ha(peer->ha);
        if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT))
                apeerobjs--;
-       else if (ast_test_flag(&peer->flags[0], SIP_REALTIME))
+       else if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && ast_test_flag(&peer->flags[0], SIP_REALTIME))
                rpeerobjs--;
        else
                speerobjs--;
@@ -2978,7 +2978,7 @@ static void sip_destroy_user(struct sip_user *user)
                ast_variables_destroy(user->chanvars);
                user->chanvars = NULL;
        }
-       if (ast_test_flag(&user->flags[0], SIP_REALTIME))
+       if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && ast_test_flag(&user->flags[0], SIP_REALTIME))
                ruserobjs--;
        else
                suserobjs--;
@@ -11477,6 +11477,7 @@ static int sip_prune_realtime(int fd, int argc, char *argv[])
        int multi = FALSE;
        char *name = NULL;
        regex_t regexbuf;
+       int havepattern = 0;
 
        switch (argc) {
        case 4:
@@ -11535,8 +11536,10 @@ static int sip_prune_realtime(int fd, int argc, char *argv[])
        }
 
        if (multi && name) {
-               if (regcomp(&regexbuf, name, REG_EXTENDED | REG_NOSUB))
+               if (regcomp(&regexbuf, name, REG_EXTENDED | REG_NOSUB)) {
                        return RESULT_SHOWUSAGE;
+               }
+               havepattern = 1;
        }
 
        if (multi) {
@@ -11611,6 +11614,10 @@ static int sip_prune_realtime(int fd, int argc, char *argv[])
                }
        }
 
+       if (havepattern) {
+               regfree(&regexbuf);
+       }
+
        return RESULT_SUCCESS;
 }