summaryrefslogtreecommitdiff
path: root/c_src
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2016-02-11 03:55:30 +0100
committerLinus Nordberg <linus@nordu.net>2016-04-25 13:14:10 +0200
commit0e75235f777648f4416d60e2c0f0940c7f1465fb (patch)
tree0b65ef6d83b5625c787729b0c5e062ae03154e84 /c_src
parent43cbe3fdd2ba375b278d198d52f700b2accf65f6 (diff)
Free data correctly. Exit from permdbtest on error.
Diffstat (limited to 'c_src')
-rw-r--r--c_src/Makefile2
-rw-r--r--c_src/permdb.c8
-rw-r--r--c_src/permdbtest.c4
3 files changed, 11 insertions, 3 deletions
diff --git a/c_src/Makefile b/c_src/Makefile
index c58dc9e..9a6c0a4 100644
--- a/c_src/Makefile
+++ b/c_src/Makefile
@@ -22,7 +22,7 @@ LOCAL_LDFLAGS =
CC = gcc
CFLAGS = -Wall -Werror -std=gnu99 $(LOCAL_CFLAGS) $(OS_CFLAGS)
-LDFLAGS = $(LOCAL_CFLAGS) -lnettle $(OS_LDFLAGS)
+LDFLAGS = $(LOCAL_LDFLAGS) -lnettle $(OS_LDFLAGS)
PORTS = fsynchelper hsmhelper permdbport
OTHER_BIN = permdb.so permdbtest
diff --git a/c_src/permdb.c b/c_src/permdb.c
index 57a09d3..bada31f 100644
--- a/c_src/permdb.c
+++ b/c_src/permdb.c
@@ -349,6 +349,7 @@ verify_index_commit(buffered_file *file, node_offset offset)
if (memcmp(data + sizeof(uint64_t) + SHA256_DIGEST_SIZE, &index_commit_cookie, sizeof(index_commit_cookie)) != 0) {
fprintf(stderr, "verifying index file: incorrect commit cookie\n");
+ free(data);
return -1;
}
struct commit_info commit;
@@ -358,6 +359,7 @@ verify_index_commit(buffered_file *file, node_offset offset)
commit.start = offset - commit.length;
memcpy(commit.checksum, data + sizeof(uint64_t), SHA256_DIGEST_SIZE);
+ free(data);
return validate_checksum(&commit, file);
}
@@ -386,7 +388,7 @@ int
datafile_verify_file(buffered_file *file)
{
unsigned char *header = read_from_file(file, sizeof(data_file_cookie), 0);
- if (memcmp(header, &data_file_cookie, sizeof(data_file_cookie)) != 0) {
+ if (header == NULL || memcmp(header, &data_file_cookie, sizeof(data_file_cookie)) != 0) {
free(header);
return -1;
}
@@ -416,7 +418,8 @@ struct commit_info *
read_data_commit(buffered_file *file, node_offset *offset)
{
unsigned char *data = read_from_file(file, sizeof(uint32_t) + SHA256_DIGEST_SIZE + sizeof(data_commit_end_cookie), *offset);
- if (memcmp(data + sizeof(uint32_t) + SHA256_DIGEST_SIZE, data_commit_end_cookie, sizeof(data_commit_end_cookie)) != 0) {
+ if (data == NULL || memcmp(data + sizeof(uint32_t) + SHA256_DIGEST_SIZE, data_commit_end_cookie, sizeof(data_commit_end_cookie)) != 0) {
+ free(data);
return NULL;
}
*offset += sizeof(uint32_t);
@@ -427,6 +430,7 @@ read_data_commit(buffered_file *file, node_offset *offset)
commit->start = *offset - commit->length;
memcpy(&commit->checksum, data + sizeof(uint32_t), SHA256_DIGEST_SIZE);
*offset += SHA256_DIGEST_SIZE + sizeof(data_commit_end_cookie);
+ free(data);
return commit;
}
diff --git a/c_src/permdbtest.c b/c_src/permdbtest.c
index 0d3bab7..7fb17b7 100644
--- a/c_src/permdbtest.c
+++ b/c_src/permdbtest.c
@@ -60,6 +60,10 @@ main(int argc, char *argv[])
permdb_object *state = permdb_alloc(store);
+ if (state == NULL) {
+ errx(1, "permdb object creation failed\n");
+ }
+
printf("generating test data\n");
void *testdata = gentestdata(nentries);
printf("inserting test data\n");