1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-02 01:17:52 +03:00

Improve sftp_new() and sftp_free().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@569 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-22 13:59:13 +00:00
parent afe0c8b2b5
commit f59630cbbc

View File

@@ -44,36 +44,45 @@ static void sftp_message_free(SFTP_MESSAGE *msg);
static void sftp_set_error(SFTP_SESSION *sftp, int errnum); static void sftp_set_error(SFTP_SESSION *sftp, int errnum);
SFTP_SESSION *sftp_new(SSH_SESSION *session){ SFTP_SESSION *sftp_new(SSH_SESSION *session){
SFTP_SESSION *sftp; SFTP_SESSION *sftp;
enter_function(); enter_function();
sftp = malloc(sizeof(SFTP_SESSION)); if (session == NULL) {
if (sftp == NULL) {
return NULL;
}
memset(sftp,0,sizeof(SFTP_SESSION));
sftp->session=session;
sftp->channel=channel_new(session);
if (sftp->channel == NULL) {
SAFE_FREE(sftp);
leave_function();
return NULL;
}
if(channel_open_session(sftp->channel)){
channel_free(sftp->channel);
free(sftp);
leave_function();
return NULL;
}
if(channel_request_sftp(sftp->channel)){
sftp_free(sftp);
leave_function();
return NULL;
}
leave_function(); leave_function();
return sftp; return NULL;
}
sftp = malloc(sizeof(SFTP_SESSION));
if (sftp == NULL) {
leave_function();
return NULL;
}
memset(sftp,0,sizeof(SFTP_SESSION));
sftp->session = session;
sftp->channel = channel_new(session);
if (sftp->channel == NULL) {
SAFE_FREE(sftp);
leave_function();
return NULL;
}
if (channel_open_session(sftp->channel)) {
channel_free(sftp->channel);
SAFE_FREE(sftp);
leave_function();
return NULL;
}
if (channel_request_sftp(sftp->channel)) {
sftp_free(sftp);
leave_function();
return NULL;
}
leave_function();
return sftp;
} }
#ifdef WITH_SERVER #ifdef WITH_SERVER
@@ -136,19 +145,26 @@ int sftp_server_init(SFTP_SESSION *sftp){
#endif /* WITH_SERVER */ #endif /* WITH_SERVER */
void sftp_free(SFTP_SESSION *sftp){ void sftp_free(SFTP_SESSION *sftp){
struct request_queue *ptr; struct request_queue *ptr;
channel_send_eof(sftp->channel);
ptr=sftp->queue; if (sftp == NULL) {
while(ptr){ return;
struct request_queue *old; }
sftp_message_free(ptr->message);
old=ptr->next; channel_send_eof(sftp->channel);
free(ptr); ptr = sftp->queue;
ptr=old; while(ptr) {
} struct request_queue *old;
channel_free(sftp->channel); sftp_message_free(ptr->message);
memset(sftp,0,sizeof(*sftp)); old = ptr->next;
free(sftp); SAFE_FREE(ptr);
ptr = old;
}
channel_free(sftp->channel);
memset(sftp, 0, sizeof(*sftp));
SAFE_FREE(sftp);
} }
int sftp_packet_write(SFTP_SESSION *sftp,u8 type, BUFFER *payload){ int sftp_packet_write(SFTP_SESSION *sftp,u8 type, BUFFER *payload){