channel: reduce duplicated free and returns

Simplified the code by trying to free data and return on a single
spot.
This commit is contained in:
Daniel Stenberg 2010-04-24 13:30:32 +02:00
parent 046ff03c3f
commit c5602fac58

View File

@ -501,25 +501,21 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
LIBSSH2_LISTENER *listener;
listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER));
if (!listener) {
if (!listener)
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle;
return NULL;
}
else {
memset(listener, 0, sizeof(LIBSSH2_LISTENER));
listener->session = session;
listener->host =
LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1);
if (!listener->host) {
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, listener);
LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle;
return NULL;
listener = NULL;
}
else {
listener->session = session;
memcpy(listener->host, host ? host : "0.0.0.0",
session->fwdLstn_host_len);
listener->host[session->fwdLstn_host_len] = 0;
@ -528,9 +524,9 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Dynamic tcpip-forward port allocated: %d",
listener->port);
} else {
listener->port = port;
}
else
listener->port = port;
listener->queue_size = 0;
listener->queue_maxsize = queue_maxsize;
@ -541,13 +537,14 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (bound_port) {
*bound_port = listener->port;
}
}
}
LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle;
return listener;
}
if (data[0] == SSH_MSG_REQUEST_FAILURE) {
else if (data[0] == SSH_MSG_REQUEST_FAILURE) {
LIBSSH2_FREE(session, data);
_libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED,
"Unable to complete request for forward-listen");