Change the behavior of ao2_link(). Previously, in inherited a reference.

Now, it automatically increases the reference count to reflect the reference
that is now held by the container.

This was done to be more consistent with ao2_unlink(), which automatically
releases the reference held by the container.  It also makes it so it is
no longer possible for a pointer to be invalid after ao2_link() returns.


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@90348 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2007-11-30 19:26:04 +00:00
parent 82757dfaa1
commit 1f8caa100d
5 changed files with 23 additions and 18 deletions

View File

@@ -2740,7 +2740,7 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
if (peer->expire == -1)
peer_unref(peer);
}
ao2_link(peers, peer_ref(peer));
ao2_link(peers, peer);
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
} else {
@@ -2797,7 +2797,7 @@ static struct iax2_user *realtime_user(const char *username)
if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
ast_set_flag(user, IAX_RTCACHEFRIENDS);
ao2_link(users, user_ref(user));
ao2_link(users, user);
} else {
ast_set_flag(user, IAX_TEMPONLY);
}
@@ -9801,14 +9801,14 @@ static int set_config(char *config_file, int reload)
user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
if (user) {
__ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
user = NULL;
user = user_unref(user);
}
peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
if (peer) {
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
__ao2_link(peers, peer, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
peer = NULL;
peer = peer_unref(peer);
}
}
if (ast_true(registeriax) || (!registeriax && genregisteriax)) {
@@ -9845,7 +9845,7 @@ static int set_config(char *config_file, int reload)
user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
if (user) {
__ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
user = NULL;
user = user_unref(user);
}
}
if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
@@ -9854,7 +9854,7 @@ static int set_config(char *config_file, int reload)
if (ast_test_flag(peer, IAX_DYNAMIC))
reg_source_db(peer);
__ao2_link(peers, peer, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
peer = NULL;
peer = peer_unref(peer);
}
} else if (strcasecmp(utype, "user")) {
ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config_file);