summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-07 13:48:34 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-07 13:48:34 +0000
commitfe2bc30984af5487c1871f80c31d2911ec70bc89 (patch)
tree02245a17171718fa0f6798ce072178fd08cc88e1
parentd1fefb4de36d8a5a95052b6f933cdb3403ee2306 (diff)
downloadlibssh-fe2bc30984af5487c1871f80c31d2911ec70bc89.tar.gz
libssh-fe2bc30984af5487c1871f80c31d2911ec70bc89.tar.xz
libssh-fe2bc30984af5487c1871f80c31d2911ec70bc89.zip
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
-rw-r--r--libssh/buffer.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/libssh/buffer.c b/libssh/buffer.c
index 7e4a80f..32a1f5b 100644
--- a/libssh/buffer.c
+++ b/libssh/buffer.c
@@ -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;
}