mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 02:37:10 +00:00 
			
		
		
		
	Audit of ao2_iterator_init() usage for v1.8.
Fixes numerous reference leaks and missing ao2_iterator_destroy() calls as a result. Review: https://reviewboard.asterisk.org/r/1697/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@352955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		| @@ -2560,6 +2560,7 @@ static char *handle_cli_iax2_show_callno_limits(struct ast_cli_entry *e, int cmd | ||||
| 			sin.sin_addr.s_addr = peercnt->addr; | ||||
| 			if (a->argc == 5 && (!strcasecmp(a->argv[4], ast_inet_ntoa(sin.sin_addr)))) { | ||||
| 					ast_cli(a->fd, "%-15s %-12d %-12d\n", ast_inet_ntoa(sin.sin_addr), peercnt->cur, peercnt->limit); | ||||
| 					ao2_ref(peercnt, -1); | ||||
| 					found = 1; | ||||
| 					break; | ||||
| 			} else { | ||||
| @@ -6580,8 +6581,7 @@ static char *handle_cli_iax2_show_users(struct ast_cli_entry *e, int cmd, struct | ||||
|  | ||||
| 	ast_cli(a->fd, FORMAT, "Username", "Secret", "Authen", "Def.Context", "A/C","Codec Pref"); | ||||
| 	i = ao2_iterator_init(users, 0); | ||||
| 	for (user = ao2_iterator_next(&i); user;  | ||||
| 		user_unref(user), user = ao2_iterator_next(&i)) { | ||||
| 	for (; (user = ao2_iterator_next(&i)); user_unref(user)) { | ||||
| 		if (havepattern && regexec(®exbuf, user->name, 0, NULL, 0)) | ||||
| 			continue; | ||||
|  | ||||
| @@ -6669,8 +6669,7 @@ static int __iax2_show_peers(int fd, int *total, struct mansession *s, const int | ||||
| 		ast_cli(fd, FORMAT2, "Name/Username", "Host", "   ", "Mask", "Port", "   ", "Status"); | ||||
|  | ||||
| 	i = ao2_iterator_init(peers, 0); | ||||
| 	for (peer = ao2_iterator_next(&i); peer; | ||||
| 		peer_unref(peer), peer = ao2_iterator_next(&i)) { | ||||
| 	for (; (peer = ao2_iterator_next(&i)); peer_unref(peer)) { | ||||
| 		char nm[20]; | ||||
| 		char status[20]; | ||||
| 		int retstatus; | ||||
| @@ -6993,7 +6992,7 @@ static int manager_iax2_show_peer_list(struct mansession *s, const struct messag | ||||
|  | ||||
|  | ||||
| 	i = ao2_iterator_init(peers, 0); | ||||
| 	for (peer = ao2_iterator_next(&i); peer; peer_unref(peer), peer = ao2_iterator_next(&i)) { | ||||
| 	for (; (peer = ao2_iterator_next(&i)); peer_unref(peer)) { | ||||
| 		encmethods_to_str(peer->encmethods, encmethods); | ||||
| 		astman_append(s, "Event: PeerEntry\r\n%sChanneltype: IAX\r\n", idtext); | ||||
| 		if (!ast_strlen_zero(peer->username)) { | ||||
| @@ -7576,8 +7575,8 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies | ||||
| 		return res; | ||||
| 	} | ||||
| 	/* Search the userlist for a compatible entry, and fill in the rest */ | ||||
| 	i = ao2_iterator_init(users, 0); | ||||
| 	ast_sockaddr_from_sin(&addr, sin); | ||||
| 	i = ao2_iterator_init(users, 0); | ||||
| 	while ((user = ao2_iterator_next(&i))) { | ||||
| 		if ((ast_strlen_zero(iaxs[callno]->username) ||				/* No username specified */ | ||||
| 			!strcmp(iaxs[callno]->username, user->name))	/* Or this username specified */ | ||||
| @@ -14574,10 +14573,9 @@ static int users_data_provider_get(const struct ast_data_search *search, | ||||
| 	char *pstr = ""; | ||||
|  | ||||
| 	i = ao2_iterator_init(users, 0); | ||||
| 	while ((user = ao2_iterator_next(&i))) { | ||||
| 	for (; (user = ao2_iterator_next(&i)); user_unref(user)) { | ||||
| 		data_user = ast_data_add_node(data_root, "user"); | ||||
| 		if (!data_user) { | ||||
| 			user_unref(user); | ||||
| 			continue; | ||||
| 		} | ||||
|  | ||||
| @@ -14626,8 +14624,6 @@ static int users_data_provider_get(const struct ast_data_search *search, | ||||
| 		} | ||||
| 		ast_data_add_str(data_user, "codec-preferences", pstr); | ||||
|  | ||||
| 		user_unref(user); | ||||
|  | ||||
| 		if (!ast_data_search_match(search, data_user)) { | ||||
| 			ast_data_remove_node(data_root, data_user); | ||||
| 		} | ||||
|   | ||||
| @@ -17017,8 +17017,8 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli | ||||
| 			while ((pi = ao2_t_iterator_next(&i, "iterate thru peers table"))) { | ||||
| 				ao2_lock(pi); | ||||
| 				if (name && regexec(®exbuf, pi->name, 0, NULL, 0)) { | ||||
| 					unref_peer(pi, "toss iterator peer ptr before continue"); | ||||
| 					ao2_unlock(pi); | ||||
| 					unref_peer(pi, "toss iterator peer ptr before continue"); | ||||
| 					continue; | ||||
| 				}; | ||||
| 				if (ast_test_flag(&pi->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { | ||||
| @@ -30019,6 +30019,8 @@ static int peers_data_provider_get(const struct ast_data_search *search, | ||||
| 		/* transfer mode */ | ||||
| 		enum_node = ast_data_add_node(data_peer, "allowtransfer"); | ||||
| 		if (!enum_node) { | ||||
| 			ao2_unlock(peer); | ||||
| 			ao2_ref(peer, -1); | ||||
| 			continue; | ||||
| 		} | ||||
| 		ast_data_add_str(enum_node, "text", transfermode2str(peer->allowtransfer)); | ||||
| @@ -30058,6 +30060,8 @@ static int peers_data_provider_get(const struct ast_data_search *search, | ||||
| 		/* amaflags */ | ||||
| 		enum_node = ast_data_add_node(data_peer, "amaflags"); | ||||
| 		if (!enum_node) { | ||||
| 			ao2_unlock(peer); | ||||
| 			ao2_ref(peer, -1); | ||||
| 			continue; | ||||
| 		} | ||||
| 		ast_data_add_int(enum_node, "value", peer->amaflags); | ||||
| @@ -30066,6 +30070,8 @@ static int peers_data_provider_get(const struct ast_data_search *search, | ||||
| 		/* sip options */ | ||||
| 		data_sip_options = ast_data_add_node(data_peer, "sipoptions"); | ||||
| 		if (!data_sip_options) { | ||||
| 			ao2_unlock(peer); | ||||
| 			ao2_ref(peer, -1); | ||||
| 			continue; | ||||
| 		} | ||||
| 		for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { | ||||
| @@ -30075,6 +30081,8 @@ static int peers_data_provider_get(const struct ast_data_search *search, | ||||
| 		/* callingpres */ | ||||
| 		enum_node = ast_data_add_node(data_peer, "callingpres"); | ||||
| 		if (!enum_node) { | ||||
| 			ao2_unlock(peer); | ||||
| 			ao2_ref(peer, -1); | ||||
| 			continue; | ||||
| 		} | ||||
| 		ast_data_add_int(enum_node, "value", peer->callingpres); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user