summaryrefslogtreecommitdiffstats
path: root/libssh
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-07 14:02:24 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-07 14:02:24 +0000
commit8d3a43db7ad387db6369cbf77323cf21b60c494a (patch)
tree1301d821cea70ff08b68b01938ea57d960132f1c /libssh
parent7059e05a2a96baf8cdadf5621ff6255ec9267bfa (diff)
downloadlibssh-8d3a43db7ad387db6369cbf77323cf21b60c494a.tar.gz
libssh-8d3a43db7ad387db6369cbf77323cf21b60c494a.tar.xz
libssh-8d3a43db7ad387db6369cbf77323cf21b60c494a.zip
Improve channel_new().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@413 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/channels.c56
1 files changed, 35 insertions, 21 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index 04242cab..c024799e 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -44,30 +44,44 @@
/** \brief allocate a new channel
* \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=malloc(sizeof(CHANNEL));
+CHANNEL *channel_new(SSH_SESSION *session) {
+ CHANNEL *channel = NULL;
- if (channel == NULL) {
- return NULL;
- }
- memset(channel,0,sizeof(CHANNEL));
- channel->session=session;
- channel->version=session->version;
- channel->stdout_buffer=buffer_new();
- channel->stderr_buffer=buffer_new();
- channel->exit_status=-1;
- if(!session->channels){
- session->channels=channel;
- channel->next=channel->prev=channel;
- return channel;
- }
- channel->next=session->channels;
- channel->prev=session->channels->prev;
- channel->next->prev=channel;
- channel->prev->next=channel;
+ channel = malloc(sizeof(CHANNEL));
+ if (channel == NULL) {
+ return NULL;
+ }
+ memset(channel,0,sizeof(CHANNEL));
+
+ channel->stdout_buffer = buffer_new();
+ if (channel->stdout_buffer == NULL) {
+ SAFE_FREE(channel);
+ return NULL;
+ }
+
+ channel->stderr_buffer = buffer_new();
+ if (channel->stderr_buffer == NULL) {
+ SAFE_FREE(channel);
+ return NULL;
+ }
+
+ 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;
+ }
+ 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){