Improve channel_new().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@413 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-07 14:02:24 +00:00
parent 7059e05a2a
commit 8d3a43db7a

View File

@@ -44,30 +44,44 @@
/** \brief allocate a new channel /** \brief allocate a new channel
* \param session ssh session * \param session ssh session
* \return an allocated channel. As this function doesn't speak with server, it never fails * \return An allocated channel, NULL on error.
*/ */
CHANNEL *channel_new(SSH_SESSION *session){ CHANNEL *channel_new(SSH_SESSION *session) {
CHANNEL *channel=malloc(sizeof(CHANNEL)); CHANNEL *channel = NULL;
if (channel == NULL) { channel = malloc(sizeof(CHANNEL));
return NULL; if (channel == NULL) {
} return NULL;
memset(channel,0,sizeof(CHANNEL)); }
channel->session=session; memset(channel,0,sizeof(CHANNEL));
channel->version=session->version;
channel->stdout_buffer=buffer_new(); channel->stdout_buffer = buffer_new();
channel->stderr_buffer=buffer_new(); if (channel->stdout_buffer == NULL) {
channel->exit_status=-1; SAFE_FREE(channel);
if(!session->channels){ return NULL;
session->channels=channel; }
channel->next=channel->prev=channel;
return channel; channel->stderr_buffer = buffer_new();
} if (channel->stderr_buffer == NULL) {
channel->next=session->channels; SAFE_FREE(channel);
channel->prev=session->channels->prev; return NULL;
channel->next->prev=channel; }
channel->prev->next=channel;
channel->session = session;
channel->version = session->version;
channel->exit_status = -1;
if(session->channels == NULL) {
session->channels = channel;
channel->next = channel->prev = channel;
return channel; return channel;
}
channel->next = session->channels;
channel->prev = session->channels->prev;
channel->next->prev = channel;
channel->prev->next = channel;
return channel;
} }
u32 ssh_channel_new_id(SSH_SESSION *session){ u32 ssh_channel_new_id(SSH_SESSION *session){