Merged revisions 377324,377329-377330 via svnmerge from

file:///srv/subversion/repos/asterisk/trunk

................
  r377324 | mjordan | 2012-12-06 08:26:13 -0600 (Thu, 06 Dec 2012) | 13 lines
  
  Fix memory leak in 'manager show event' when command entered incorrectly
  
  When the CLI command 'manager show event' was run incorrectly and its usage
  instructions returned, a reference to the event container was leaked. This
  would prevent the container from being reclaimed when Asterisk exits. We now
  properly decrement the count on the ao2 object using the nifty RAII_VAR macro.
  
  Thanks to Russell for helping me stumble on this, and Terry for writing that
  ridiculously helpful macro.
  ........
  
  Merged revisions 377319 from http://svn.asterisk.org/svn/asterisk/branches/11
................
  r377329 | russell | 2012-12-06 09:06:47 -0600 (Thu, 06 Dec 2012) | 7 lines
  
  Add CLI tab completion to 'acl show'.
  
  The 'acl show' CLI command allows you to show the details about a specific
  named ACL in acl.conf.  This patch adds tab completion to the command.
  
  Review: https://reviewboard.asterisk.org/r/2230/
................
  r377330 | russell | 2012-12-06 09:13:37 -0600 (Thu, 06 Dec 2012) | 6 lines
  
  Minor code cleanup in named_acl.c.
  
  This patch makes a few little cleanups to named_acl.c.  A couple non-public
  functions were made static and an opening brace for a function was moved to
  its own line, per the coding guidelines.
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377335 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/78/78/1
Automerge script 13 years ago
parent 7a203dc72c
commit 95b571b390

@ -7149,7 +7149,7 @@ static char *handle_manager_show_events(struct ast_cli_entry *e, int cmd, struct
static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
struct ao2_container *events; RAII_VAR(struct ao2_container *, events, NULL, ao2_cleanup);
struct ao2_iterator it_events; struct ao2_iterator it_events;
struct ast_xml_doc_item *item, *temp; struct ast_xml_doc_item *item, *temp;
int length; int length;
@ -7184,7 +7184,6 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct
ao2_ref(item, -1); ao2_ref(item, -1);
} }
ao2_iterator_destroy(&it_events); ao2_iterator_destroy(&it_events);
ao2_ref(events, -1);
return match; return match;
} }
@ -7194,7 +7193,6 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct
if (!(item = ao2_find(events, a->argv[3], OBJ_KEY))) { if (!(item = ao2_find(events, a->argv[3], OBJ_KEY))) {
ast_cli(a->fd, "Could not find event '%s'\n", a->argv[3]); ast_cli(a->fd, "Could not find event '%s'\n", a->argv[3]);
ao2_ref(events, -1);
return CLI_SUCCESS; return CLI_SUCCESS;
} }
@ -7234,7 +7232,6 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct
} }
ao2_ref(item, -1); ao2_ref(item, -1);
ao2_ref(events, -1);
return CLI_SUCCESS; return CLI_SUCCESS;
} }

@ -177,7 +177,7 @@ static void destroy_named_acl(void *obj)
* \retval NULL failure * \retval NULL failure
*\retval non-NULL successfully allocated named ACL *\retval non-NULL successfully allocated named ACL
*/ */
void *named_acl_alloc(const char *cat) static void *named_acl_alloc(const char *cat)
{ {
struct named_acl *named_acl; struct named_acl *named_acl;
@ -198,7 +198,7 @@ void *named_acl_alloc(const char *cat)
* \param cat name of the ACL wanted to be found * \param cat name of the ACL wanted to be found
* \retval pointer to the named ACL if available. Null if not found. * \retval pointer to the named ACL if available. Null if not found.
*/ */
void *named_acl_find(struct ao2_container *container, const char *cat) static void *named_acl_find(struct ao2_container *container, const char *cat)
{ {
struct named_acl tmp; struct named_acl tmp;
ast_copy_string(tmp.name, cat, sizeof(tmp.name)); ast_copy_string(tmp.name, cat, sizeof(tmp.name));
@ -309,7 +309,8 @@ static struct named_acl *named_acl_find_realtime(const char *name)
return acl; return acl;
} }
struct ast_ha *ast_named_acl_find(const char *name, int *is_realtime, int *is_undefined) { struct ast_ha *ast_named_acl_find(const char *name, int *is_realtime, int *is_undefined)
{
struct ast_ha *ha = NULL; struct ast_ha *ha = NULL;
RAII_VAR(struct named_acl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); RAII_VAR(struct named_acl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
@ -503,6 +504,13 @@ static void cli_display_named_acl_list(int fd)
/* \brief ACL command show <name> */ /* \brief ACL command show <name> */
static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{ {
RAII_VAR(struct named_acl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
int length;
int which;
struct ao2_iterator i;
struct named_acl *named_acl;
char *match = NULL;
switch (cmd) { switch (cmd) {
case CLI_INIT: case CLI_INIT:
e->command = "acl show"; e->command = "acl show";
@ -511,7 +519,23 @@ static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct
" Shows a list of named ACLs or lists all entries in a given named ACL.\n"; " Shows a list of named ACLs or lists all entries in a given named ACL.\n";
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
return NULL; if (!cfg) {
return NULL;
}
length = strlen(a->word);
which = 0;
i = ao2_iterator_init(cfg->named_acl_list, 0);
while ((named_acl = ao2_iterator_next(&i))) {
if (!strncasecmp(a->word, named_acl->name, length) && ++which > a->n) {
match = ast_strdup(named_acl->name);
ao2_ref(named_acl, -1);
break;
}
ao2_ref(named_acl, -1);
}
ao2_iterator_destroy(&i);
return match;
} }
if (a->argc == 2) { if (a->argc == 2) {

Loading…
Cancel
Save