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,53 +501,50 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
LIBSSH2_LISTENER *listener; LIBSSH2_LISTENER *listener;
listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER)); listener = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_LISTENER));
if (!listener) { if (!listener)
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for listener queue"); "Unable to allocate memory for listener queue");
LIBSSH2_FREE(session, data); else {
session->fwdLstn_state = libssh2_NB_state_idle; memset(listener, 0, sizeof(LIBSSH2_LISTENER));
return NULL; listener->host =
} LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1);
memset(listener, 0, sizeof(LIBSSH2_LISTENER)); if (!listener->host) {
listener->session = session; _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
listener->host = "Unable to allocate memory for listener queue");
LIBSSH2_ALLOC(session, session->fwdLstn_host_len + 1); LIBSSH2_FREE(session, listener);
if (!listener->host) { listener = NULL;
_libssh2_error(session, LIBSSH2_ERROR_ALLOC, }
"Unable to allocate memory for listener queue"); else {
LIBSSH2_FREE(session, listener); listener->session = session;
LIBSSH2_FREE(session, data); memcpy(listener->host, host ? host : "0.0.0.0",
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_host_len);
return NULL; listener->host[session->fwdLstn_host_len] = 0;
} if (data_len >= 5 && !port) {
memcpy(listener->host, host ? host : "0.0.0.0", listener->port = _libssh2_ntohu32(data + 1);
session->fwdLstn_host_len); _libssh2_debug(session, LIBSSH2_TRACE_CONN,
listener->host[session->fwdLstn_host_len] = 0; "Dynamic tcpip-forward port allocated: %d",
if (data_len >= 5 && !port) { listener->port);
listener->port = _libssh2_ntohu32(data + 1); }
_libssh2_debug(session, LIBSSH2_TRACE_CONN, else
"Dynamic tcpip-forward port allocated: %d", listener->port = port;
listener->port);
} else {
listener->port = port;
}
listener->queue_size = 0; listener->queue_size = 0;
listener->queue_maxsize = queue_maxsize; listener->queue_maxsize = queue_maxsize;
/* append this to the parent's list of listeners */ /* append this to the parent's list of listeners */
_libssh2_list_add(&session->listeners, &listener->node); _libssh2_list_add(&session->listeners, &listener->node);
if (bound_port) { if (bound_port) {
*bound_port = listener->port; *bound_port = listener->port;
}
}
} }
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
session->fwdLstn_state = libssh2_NB_state_idle; session->fwdLstn_state = libssh2_NB_state_idle;
return listener; return listener;
} }
else if (data[0] == SSH_MSG_REQUEST_FAILURE) {
if (data[0] == SSH_MSG_REQUEST_FAILURE) {
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
_libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED, _libssh2_error(session, LIBSSH2_ERROR_REQUEST_DENIED,
"Unable to complete request for forward-listen"); "Unable to complete request for forward-listen");