diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-27 16:22:32 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-27 16:22:32 +0200 |
commit | 0e1575d03f243e86ae65723458f3c1dbbb20ec70 (patch) | |
tree | d5afb0c4a1d6b8000f0485d70b755126a649b6bb /src | |
parent | m fixes + doc (diff) | |
download | mds-0e1575d03f243e86ae65723458f3c1dbbb20ec70.tar.gz mds-0e1575d03f243e86ae65723458f3c1dbbb20ec70.tar.bz2 mds-0e1575d03f243e86ae65723458f3c1dbbb20ec70.tar.xz |
doc
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libmdsserver/mds-message.c | 11 |
1 files changed, 9 insertions, 2 deletions
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; |