From ea16a5daa21ad5219bab2c7ef78eaeb2d023e6d2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 24 Jan 2013 16:43:56 -0500 Subject: [PATCH] fix some resulting segfaults --- daemon/bencode.c | 1 + daemon/bencode.h | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/daemon/bencode.c b/daemon/bencode.c index 649e30fd0..dd417602b 100644 --- a/daemon/bencode.c +++ b/daemon/bencode.c @@ -84,6 +84,7 @@ int bencode_buffer_init(bencode_buffer_t *buf) { buf->pieces = __bencode_piece_new(0); if (!buf->pieces) return -1; + buf->free_list = NULL; return 0; } diff --git a/daemon/bencode.h b/daemon/bencode.h index 76c878d70..91f7ed95e 100644 --- a/daemon/bencode.h +++ b/daemon/bencode.h @@ -97,10 +97,9 @@ static inline bencode_item_t *bencode_dictionary_add_string(bencode_item_t *dict /* Ditto, but for a "str" object */ static inline bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, const char *key, const str *val); -/* Ditto again, but adds the buffer which contains the string (val->s) to the bencode_buffer_t's - * internal free list. When the bencode_item_t object is destroyed, BENCODE_FREE will be called - * on this buffer. */ -static inline bencode_item_t *bencode_dictionary_add_str_free(bencode_item_t *dict, const char *key, const str *val); +/* Ditto again, but adds the str object (val) to the bencode_buffer_t's internal free list. When + * the bencode_item_t object is destroyed, BENCODE_FREE will be called on this pointer. */ +static inline bencode_item_t *bencode_dictionary_add_str_free(bencode_item_t *dict, const char *key, str *val); /* Convenience function to add an integer value to a dictionary */ static inline bencode_item_t *bencode_dictionary_add_integer(bencode_item_t *dict, const char *key, long long int val); @@ -275,10 +274,10 @@ static inline bencode_item_t *bencode_dictionary_add_str(bencode_item_t *dict, c return bencode_dictionary_add(dict, key, bencode_str(dict->buffer, val)); } -static inline bencode_item_t *bencode_dictionary_add_str_free(bencode_item_t *dict, const char *key, const str *val) { +static inline bencode_item_t *bencode_dictionary_add_str_free(bencode_item_t *dict, const char *key, str *val) { if (!val) return NULL; - bencode_buffer_freelist_add(dict->buffer, val->s); + bencode_buffer_freelist_add(dict->buffer, val); return bencode_dictionary_add(dict, key, bencode_str(dict->buffer, val)); }