Fix a memory leak in realloc_buffer.
If realloc fails, the original block is left untouched. So don't overwrite it that we can free it. git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@411 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
d1fefb4de3
Коммит
fe2bc30984
@ -68,16 +68,19 @@ void buffer_free(struct buffer_struct *buffer) {
|
||||
|
||||
static int realloc_buffer(struct buffer_struct *buffer, int needed) {
|
||||
int smallest = 1;
|
||||
char *new = NULL;
|
||||
/* Find the smallest power of two which is greater or equal to needed */
|
||||
while(smallest <= needed) {
|
||||
smallest <<= 1;
|
||||
}
|
||||
needed = smallest;
|
||||
buffer->data = realloc(buffer->data, needed);
|
||||
if (buffer->data == NULL) {
|
||||
new = realloc(buffer->data, needed);
|
||||
if (new == NULL) {
|
||||
return -1;
|
||||
}
|
||||
buffer->data = new;
|
||||
buffer->allocated = needed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user