mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
don't leak almost 200 bytes for each new channel and store the active
channel list using the linked list macros (issue #6330) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8618 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include "asterisk/md5.h"
|
#include "asterisk/md5.h"
|
||||||
#include "asterisk/manager.h"
|
#include "asterisk/manager.h"
|
||||||
|
#include "asterisk/linkedlists.h"
|
||||||
|
|
||||||
#undef gethostbyname
|
#undef gethostbyname
|
||||||
|
|
||||||
@@ -60,15 +61,17 @@ static struct ast_mansession {
|
|||||||
int inlen;
|
int inlen;
|
||||||
} session;
|
} session;
|
||||||
|
|
||||||
static struct ast_chan {
|
struct ast_chan {
|
||||||
char name[80];
|
char name[80];
|
||||||
char exten[20];
|
char exten[20];
|
||||||
char context[20];
|
char context[20];
|
||||||
char priority[20];
|
char priority[20];
|
||||||
char callerid[40];
|
char callerid[40];
|
||||||
char state[10];
|
char state[10];
|
||||||
struct ast_chan *next;
|
AST_LIST_ENTRY(ast_chan) list;
|
||||||
} *chans;
|
};
|
||||||
|
|
||||||
|
static AST_LIST_HEAD_NOLOCK_STATIC(chans, ast_chan);
|
||||||
|
|
||||||
/* dummy functions to be compatible with the Asterisk core for md5.c */
|
/* dummy functions to be compatible with the Asterisk core for md5.c */
|
||||||
void ast_register_file_version(const char *file, const char *version);
|
void ast_register_file_version(const char *file, const char *version);
|
||||||
@@ -83,39 +86,31 @@ void ast_unregister_file_version(const char *file)
|
|||||||
|
|
||||||
static struct ast_chan *find_chan(char *name)
|
static struct ast_chan *find_chan(char *name)
|
||||||
{
|
{
|
||||||
struct ast_chan *prev = NULL, *chan = chans;
|
struct ast_chan *chan;
|
||||||
while(chan) {
|
AST_LIST_TRAVERSE(&chans, chan, list) {
|
||||||
if (!strcmp(name, chan->name))
|
if (!strcmp(name, chan->name))
|
||||||
return chan;
|
return chan;
|
||||||
prev = chan;
|
|
||||||
chan = chan->next;
|
|
||||||
}
|
}
|
||||||
chan = malloc(sizeof(struct ast_chan));
|
chan = malloc(sizeof(struct ast_chan));
|
||||||
if (chan) {
|
if (chan) {
|
||||||
memset(chan, 0, sizeof(struct ast_chan));
|
memset(chan, 0, sizeof(struct ast_chan));
|
||||||
strncpy(chan->name, name, sizeof(chan->name) - 1);
|
strncpy(chan->name, name, sizeof(chan->name) - 1);
|
||||||
if (prev)
|
AST_LIST_INSERT_TAIL(&chans, chan, list);
|
||||||
prev->next = chan;
|
|
||||||
else
|
|
||||||
chans = chan;
|
|
||||||
}
|
}
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void del_chan(char *name)
|
static void del_chan(char *name)
|
||||||
{
|
{
|
||||||
struct ast_chan *prev = NULL, *chan = chans;
|
struct ast_chan *chan;
|
||||||
while(chan) {
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&chans, chan, list) {
|
||||||
if (!strcmp(name, chan->name)) {
|
if (!strcmp(name, chan->name)) {
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&chans, list);
|
||||||
prev->next = chan->next;
|
free(chan);
|
||||||
else
|
|
||||||
chans = chan->next;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prev = chan;
|
|
||||||
chan = chan->next;
|
|
||||||
}
|
}
|
||||||
|
AST_LIST_TRAVERSE_SAFE_END
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fdprintf(int fd, char *fmt, ...)
|
static void fdprintf(int fd, char *fmt, ...)
|
||||||
@@ -246,8 +241,7 @@ static void rebuild_channels(newtComponent c)
|
|||||||
int x=0;
|
int x=0;
|
||||||
prev = newtListboxGetCurrent(c);
|
prev = newtListboxGetCurrent(c);
|
||||||
newtListboxClear(c);
|
newtListboxClear(c);
|
||||||
chan = chans;
|
AST_LIST_TRAVERSE(&chans, chan, list) {
|
||||||
while(chan) {
|
|
||||||
snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid);
|
snprintf(tmpn, sizeof(tmpn), "%s (%s)", chan->name, chan->callerid);
|
||||||
if (strlen(chan->exten))
|
if (strlen(chan->exten))
|
||||||
snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s",
|
snprintf(tmp, sizeof(tmp), "%-30s %8s -> %s@%s:%s",
|
||||||
@@ -258,7 +252,6 @@ static void rebuild_channels(newtComponent c)
|
|||||||
tmpn, chan->state);
|
tmpn, chan->state);
|
||||||
newtListboxAppendEntry(c, tmp, chan);
|
newtListboxAppendEntry(c, tmp, chan);
|
||||||
x++;
|
x++;
|
||||||
chan = chan->next;
|
|
||||||
}
|
}
|
||||||
if (!x)
|
if (!x)
|
||||||
newtListboxAppendEntry(c, " << No Active Channels >> ", NULL);
|
newtListboxAppendEntry(c, " << No Active Channels >> ", NULL);
|
||||||
|
Reference in New Issue
Block a user