summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-17 18:51:55 +0100
committerDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-17 18:51:55 +0100
commit112007d6308478c2dead8745024332b7299dd1a3 (patch)
treefd5f38f7488bab87232693ddcb7ce7723e72e2c0 /src/lib
parentd2bffe6cc47af18099d33b82920df0bb027da207 (diff)
downloadouroboros-112007d6308478c2dead8745024332b7299dd1a3.tar.gz
ouroboros-112007d6308478c2dead8745024332b7299dd1a3.zip
lib: fixes to du_buff
fixes memleaks in du_buff and du_buff_test fixes bug in copy operation
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/du_buff.c16
-rw-r--r--src/lib/tests/du_buff_test.c13
2 files changed, 18 insertions, 11 deletions
diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c
index 918ee57d..5345925c 100644
--- a/src/lib/du_buff.c
+++ b/src/lib/du_buff.c
@@ -46,7 +46,7 @@ struct du_buff {
size_t du_tail;
};
-void buffer_destroy(struct buffer * buf)
+static void buffer_destroy(struct buffer * buf)
{
if (buf == NULL) {
LOG_DBGF("Bogus input, bugging out.");
@@ -57,7 +57,7 @@ void buffer_destroy(struct buffer * buf)
free (buf);
}
-void buffer_destroy_list(struct buffer * head)
+static void buffer_destroy_list(struct buffer * head)
{
struct list_head * ptr;
struct list_head * n;
@@ -72,9 +72,10 @@ void buffer_destroy_list(struct buffer * head)
list_del(ptr);
buffer_destroy(tmp);
}
+ free(head);
}
-struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
+static struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
{
struct buffer * head = NULL;
size_t remaining = size;
@@ -123,6 +124,7 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
LOG_WARN("Could not allocate memory block.");
buffer_destroy_list(head);
free(head);
+ free(buf);
return NULL;
}
} else {
@@ -139,7 +141,7 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
return head;
}
-struct buffer * buffer_seek(const struct buffer * head, size_t pos)
+static struct buffer * buffer_seek(const struct buffer * head, size_t pos)
{
struct list_head * ptr = NULL;
size_t cur_buf_start = 0;
@@ -163,7 +165,7 @@ struct buffer * buffer_seek(const struct buffer * head, size_t pos)
return NULL;
}
-uint8_t * buffer_seek_pos(const struct buffer * head, size_t pos)
+static uint8_t * buffer_seek_pos(const struct buffer * head, size_t pos)
{
struct list_head * ptr = NULL;
size_t cur_buf_start = 0;
@@ -188,7 +190,7 @@ uint8_t * buffer_seek_pos(const struct buffer * head, size_t pos)
return NULL;
}
-int buffer_copy_data(struct buffer * head,
+static int buffer_copy_data(struct buffer * head,
size_t pos,
const void * src,
size_t len)
@@ -241,6 +243,7 @@ int buffer_copy_data(struct buffer * head,
else
memcpy(ptr_start, copy_pos, space_in_buf);
bytes_remaining -= space_in_buf;
+ copy_pos += space_in_buf;
}
return 0;
@@ -270,7 +273,6 @@ void du_buff_destroy(du_buff_t * dub)
return;
}
buffer_destroy_list(dub->buffer);
-
free (dub);
}
diff --git a/src/lib/tests/du_buff_test.c b/src/lib/tests/du_buff_test.c
index 2b7b5e55..bda1ca43 100644
--- a/src/lib/tests/du_buff_test.c
+++ b/src/lib/tests/du_buff_test.c
@@ -48,15 +48,20 @@ int du_buff_test(int argc, char ** argv)
if (dub == NULL)
return -1;
- if (k > DU_BLOCK_DATA_SIZE)
+ if (k > DU_BLOCK_DATA_SIZE) {
+ du_buff_destroy (dub);
continue;
+ }
- if (i - (j + k) > DU_BLOCK_DATA_SIZE)
+ if (i - (j + k) > DU_BLOCK_DATA_SIZE) {
+ du_buff_destroy (dub);
continue;
+ }
- if (du_buff_init(dub, k, bits, j) < 0)
+ if (du_buff_init(dub, k, bits, j) < 0) {
+ du_buff_destroy (dub);
return -1;
-
+ }
du_buff_destroy (dub);
}
}