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:
@@ -48,12 +48,18 @@ SFTP_SESSION *sftp_new(SSH_SESSION *session){
|
|||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
|
||||||
sftp = malloc(sizeof(SFTP_SESSION));
|
if (session == NULL) {
|
||||||
if (sftp == NULL) {
|
leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sftp = malloc(sizeof(SFTP_SESSION));
|
||||||
|
if (sftp == NULL) {
|
||||||
|
leave_function();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
memset(sftp,0,sizeof(SFTP_SESSION));
|
memset(sftp,0,sizeof(SFTP_SESSION));
|
||||||
|
|
||||||
sftp->session = session;
|
sftp->session = session;
|
||||||
sftp->channel = channel_new(session);
|
sftp->channel = channel_new(session);
|
||||||
if (sftp->channel == NULL) {
|
if (sftp->channel == NULL) {
|
||||||
@@ -61,17 +67,20 @@ SFTP_SESSION *sftp_new(SSH_SESSION *session){
|
|||||||
leave_function();
|
leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel_open_session(sftp->channel)) {
|
if (channel_open_session(sftp->channel)) {
|
||||||
channel_free(sftp->channel);
|
channel_free(sftp->channel);
|
||||||
free(sftp);
|
SAFE_FREE(sftp);
|
||||||
leave_function();
|
leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel_request_sftp(sftp->channel)) {
|
if (channel_request_sftp(sftp->channel)) {
|
||||||
sftp_free(sftp);
|
sftp_free(sftp);
|
||||||
leave_function();
|
leave_function();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return sftp;
|
return sftp;
|
||||||
}
|
}
|
||||||
@@ -137,18 +146,25 @@ int sftp_server_init(SFTP_SESSION *sftp){
|
|||||||
|
|
||||||
void sftp_free(SFTP_SESSION *sftp){
|
void sftp_free(SFTP_SESSION *sftp){
|
||||||
struct request_queue *ptr;
|
struct request_queue *ptr;
|
||||||
|
|
||||||
|
if (sftp == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
channel_send_eof(sftp->channel);
|
channel_send_eof(sftp->channel);
|
||||||
ptr = sftp->queue;
|
ptr = sftp->queue;
|
||||||
while(ptr) {
|
while(ptr) {
|
||||||
struct request_queue *old;
|
struct request_queue *old;
|
||||||
sftp_message_free(ptr->message);
|
sftp_message_free(ptr->message);
|
||||||
old = ptr->next;
|
old = ptr->next;
|
||||||
free(ptr);
|
SAFE_FREE(ptr);
|
||||||
ptr = old;
|
ptr = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
channel_free(sftp->channel);
|
channel_free(sftp->channel);
|
||||||
memset(sftp, 0, sizeof(*sftp));
|
memset(sftp, 0, sizeof(*sftp));
|
||||||
free(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){
|
||||||
|
|||||||
Reference in New Issue
Block a user