sftp: Allocate a new buffer in sftp_packet_read() if needed
We will move the buffer to the message instead of duplicating the memory. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
97d2e1f4cb
Коммит
be8302e2f3
12
src/sftp.c
12
src/sftp.c
@ -339,11 +339,23 @@ sftp_packet sftp_packet_read(sftp_session sftp)
|
|||||||
|
|
||||||
packet->sftp = sftp;
|
packet->sftp = sftp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the packet has a payload, then just reinit the buffer, otherwise
|
||||||
|
* allocate a new one.
|
||||||
|
*/
|
||||||
|
if (packet->payload != NULL) {
|
||||||
rc = ssh_buffer_reinit(packet->payload);
|
rc = ssh_buffer_reinit(packet->payload);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
ssh_set_error_oom(sftp->session);
|
ssh_set_error_oom(sftp->session);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
packet->payload = ssh_buffer_new();
|
||||||
|
if (packet->payload == NULL) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nread = 0;
|
nread = 0;
|
||||||
do {
|
do {
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user