summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2017-08-03 12:20:32 +0100
committerPhilip Withnall <withnall@endlessm.com>2017-09-12 14:26:24 +0100
commitfbdccf0c2787ebdc65fe13ac64bd25c829ea7972 (patch)
tree17f36c9684254638bf6656289c7c091afd4e96bf
parent4c4834ab634f735145c8f758a22cbdd9cab79bac (diff)
downloadlibnice-fbdccf0c2787ebdc65fe13ac64bd25c829ea7972.tar.gz
stun: Fix FD leak in test/utility code
https://phabricator.freedesktop.org/T7798 Signed-off-by: Philip Withnall <withnall@endlessm.com> Reviewed-by: Olivier CrĂȘte <olivier.crete@collabora.com> Differential Revision: https://phabricator.freedesktop.org/D1819
-rw-r--r--stun/usages/bind.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/stun/usages/bind.c b/stun/usages/bind.c
index d56790f..ee600a0 100644
--- a/stun/usages/bind.c
+++ b/stun/usages/bind.c
@@ -491,13 +491,15 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
ret = stun_trans_create (&trans, SOCK_DGRAM, 0, srv, srvlen);
if (ret != STUN_USAGE_TRANS_RETURN_SUCCESS) {
stun_debug ("STUN transaction failed: couldn't create transport.");
- return STUN_USAGE_BIND_RETURN_ERROR;
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
}
val = stun_trans_send (&trans, req_buf, len);
if (val < -1) {
stun_debug ("STUN transaction failed: couldn't send request.");
- return STUN_USAGE_BIND_RETURN_ERROR;
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
}
stun_timer_start (&timer, STUN_TIMER_DEFAULT_TIMEOUT,
@@ -514,14 +516,16 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
switch (stun_timer_refresh (&timer)) {
case STUN_USAGE_TIMER_RETURN_TIMEOUT:
stun_debug ("STUN transaction failed: time out.");
- return STUN_USAGE_BIND_RETURN_TIMEOUT; // fatal error!
+ bind_ret = STUN_USAGE_BIND_RETURN_TIMEOUT; // fatal error!
+ goto done;
case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
stun_debug ("STUN transaction retransmitted (timeout %dms).",
stun_timer_remainder (&timer));
val = stun_trans_send (&trans, req_buf, len);
if (val < -1) {
stun_debug ("STUN transaction failed: couldn't resend request.");
- return STUN_USAGE_BIND_RETURN_ERROR;
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
}
continue;
case STUN_USAGE_TIMER_RETURN_SUCCESS:
@@ -538,7 +542,10 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
valid = stun_agent_validate (&agent, &msg, buf, val, NULL, NULL);
if (valid == STUN_VALIDATION_UNKNOWN_ATTRIBUTE)
- return STUN_USAGE_BIND_RETURN_ERROR;
+ {
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
+ }
if (valid != STUN_VALIDATION_SUCCESS) {
ret = STUN_USAGE_TRANS_RETURN_RETRY;
@@ -554,12 +561,16 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
(struct sockaddr *) &alternate_server, alternate_server_len);
if (ret != STUN_USAGE_TRANS_RETURN_SUCCESS) {
- return STUN_USAGE_BIND_RETURN_ERROR;
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
}
val = stun_trans_send (&trans, req_buf, len);
if (val < -1)
- return STUN_USAGE_BIND_RETURN_ERROR;
+ {
+ bind_ret = STUN_USAGE_BIND_RETURN_ERROR;
+ goto done;
+ }
stun_timer_start (&timer, STUN_TIMER_DEFAULT_TIMEOUT,
STUN_TIMER_DEFAULT_MAX_RETRANSMISSIONS);
@@ -573,5 +584,9 @@ StunUsageBindReturn stun_usage_bind_run (const struct sockaddr *srv,
}
while (ret == STUN_USAGE_TRANS_RETURN_RETRY);
+done:
+ if (trans.fd != -1)
+ stun_trans_deinit (&trans);
+
return bind_ret;
}