From 0e1575d03f243e86ae65723458f3c1dbbb20ec70 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 27 Apr 2014 16:22:32 +0200 Subject: doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/mds-message.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/libmdsserver') diff --git a/src/libmdsserver/mds-message.c b/src/libmdsserver/mds-message.c index 3d44e19..b5ffab7 100644 --- a/src/libmdsserver/mds-message.c +++ b/src/libmdsserver/mds-message.c @@ -376,12 +376,15 @@ int mds_message_unmarshal(mds_message_t* this, char* data) this->payload_ptr = ((size_t*)data)[2]; this->buffer_ptr = ((size_t*)data)[3]; this->buffer_size = this->buffer_ptr; + data += 4 * sizeof(size_t) / sizeof(char); + + /* Make sure that the pointers are NULL so that they are + not freed without being allocated when the message is + destroyed if this function fails. */ this->headers = NULL; this->payload = NULL; this->buffer = NULL; - data += 4 * sizeof(size_t) / sizeof(char); - this->stage = ((int*)data)[0]; data += sizeof(int) / sizeof(char); @@ -404,6 +407,8 @@ int mds_message_unmarshal(mds_message_t* this, char* data) } this->buffer_size <<= 7; + /* Allocate header list, payload and read buffer. */ + if (header_count > 0) { this->headers = malloc(header_count * sizeof(char*)); @@ -422,6 +427,8 @@ int mds_message_unmarshal(mds_message_t* this, char* data) if (this->buffer == NULL) return -1; + /* Fill the header list, payload and read buffer. */ + for (i = 0; i < this->header_count; i++) { n = strlen(data) + 1; -- cgit v1.2.3-70-g09d2