summaryrefslogtreecommitdiff
path: root/trust
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-10-16 18:10:05 +0200
committerDaiki Ueno <ueno@gnu.org>2018-10-17 10:13:32 +0200
commitb10dadce5a3c921149b2c9fe0dec614f8076ebda (patch)
tree1be6432a3cd602032c4c036bcfac4fea1b1f7158 /trust
parentc76197ddbbd0c29adc2bceff2ee9f740f71d134d (diff)
build: Free memory before return{,_val}_if_* macros
Diffstat (limited to 'trust')
-rw-r--r--trust/asn1.c15
-rw-r--r--trust/builder.c5
-rw-r--r--trust/index.c10
-rw-r--r--trust/persist.c5
-rw-r--r--trust/save.c29
-rw-r--r--trust/session.c10
-rw-r--r--trust/token.c5
7 files changed, 65 insertions, 14 deletions
diff --git a/trust/asn1.c b/trust/asn1.c
index dd1812d..5ce682d 100644
--- a/trust/asn1.c
+++ b/trust/asn1.c
@@ -285,11 +285,17 @@ p11_asn1_cache_new (void)
return_val_if_fail (cache != NULL, NULL);
cache->defs = p11_asn1_defs_load ();
- return_val_if_fail (cache->defs != NULL, NULL);
+ if (cache->defs == NULL) {
+ p11_asn1_cache_free (cache);
+ return_val_if_reached (NULL);
+ }
cache->items = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal,
NULL, free_asn1_item);
- return_val_if_fail (cache->items != NULL, NULL);
+ if (cache->items == NULL) {
+ p11_asn1_cache_free (cache);
+ return_val_if_reached (NULL);
+ }
return cache;
}
@@ -342,7 +348,10 @@ p11_asn1_cache_take (p11_asn1_cache *cache,
item->length = der_len;
item->node = node;
item->struct_name = strdup (struct_name);
- return_if_fail (item->struct_name != NULL);
+ if (item->struct_name == NULL) {
+ free_asn1_item (item);
+ return_if_reached ();
+ }
if (!p11_dict_set (cache->items, (void *)der, item))
return_if_reached ();
diff --git a/trust/builder.c b/trust/builder.c
index 742c544..d819dc8 100644
--- a/trust/builder.c
+++ b/trust/builder.c
@@ -187,7 +187,10 @@ p11_builder_new (int flags)
return_val_if_fail (builder != NULL, NULL);
builder->asn1_cache = p11_asn1_cache_new ();
- return_val_if_fail (builder->asn1_cache, NULL);
+ if (builder->asn1_cache == NULL) {
+ p11_builder_free (builder);
+ return_val_if_reached (NULL);
+ }
builder->asn1_defs = p11_asn1_cache_defs (builder->asn1_cache);
builder->flags = flags;
diff --git a/trust/index.c b/trust/index.c
index f4b6b4b..6a8e535 100644
--- a/trust/index.c
+++ b/trust/index.c
@@ -170,10 +170,16 @@ p11_index_new (p11_index_build_cb build,
index->objects = p11_dict_new (p11_dict_ulongptr_hash,
p11_dict_ulongptr_equal,
NULL, free_object);
- return_val_if_fail (index->objects != NULL, NULL);
+ if (index->objects == NULL) {
+ p11_index_free (index);
+ return_val_if_reached (NULL);
+ }
index->buckets = calloc (NUM_BUCKETS, sizeof (index_bucket));
- return_val_if_fail (index->buckets != NULL, NULL);
+ if (index->buckets == NULL) {
+ p11_index_free (index);
+ return_val_if_reached (NULL);
+ }
return index;
}
diff --git a/trust/persist.c b/trust/persist.c
index 887b316..569cea1 100644
--- a/trust/persist.c
+++ b/trust/persist.c
@@ -89,7 +89,10 @@ p11_persist_new (void)
return_val_if_fail (persist != NULL, NULL);
persist->constants = p11_constant_reverse (true);
- return_val_if_fail (persist->constants != NULL, NULL);
+ if (persist->constants == NULL) {
+ free (persist);
+ return_val_if_reached (NULL);
+ }
return persist;
}
diff --git a/trust/save.c b/trust/save.c
index abff864..8184e13 100644
--- a/trust/save.c
+++ b/trust/save.c
@@ -68,6 +68,8 @@ static char * make_unique_name (const char *bare,
const char *extension,
int (*check) (void *, char *),
void *data);
+static void filo_free (p11_save_file *file);
+static void dir_free (p11_save_dir *dir);
bool
p11_save_write_and_finish (p11_save_file *file,
@@ -114,9 +116,15 @@ p11_save_open_file (const char *path,
return_val_if_fail (file != NULL, NULL);
file->temp = temp;
file->bare = strdup (path);
- return_val_if_fail (file->bare != NULL, NULL);
+ if (file->bare == NULL) {
+ filo_free (file);
+ return_val_if_reached (NULL);
+ }
file->extension = strdup (extension);
- return_val_if_fail (file->extension != NULL, NULL);
+ if (file->extension == NULL) {
+ filo_free (file);
+ return_val_if_reached (NULL);
+ }
file->flags = flags;
file->fd = fd;
@@ -166,6 +174,13 @@ filo_free (p11_save_file *file)
free (file);
}
+static void
+dir_free (p11_save_dir *dir) {
+ p11_dict_free (dir->cache);
+ free (dir->path);
+ free (dir);
+}
+
#ifdef OS_UNIX
static int
@@ -349,10 +364,16 @@ p11_save_open_directory (const char *path,
return_val_if_fail (dir != NULL, NULL);
dir->path = strdup (path);
- return_val_if_fail (dir->path != NULL, NULL);
+ if (dir->path == NULL) {
+ dir_free (dir);
+ return_val_if_reached (NULL);
+ }
dir->cache = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, NULL);
- return_val_if_fail (dir->cache != NULL, NULL);
+ if (dir->cache == NULL) {
+ dir_free (dir);
+ return_val_if_reached (NULL);
+ }
dir->flags = flags;
return dir;
diff --git a/trust/session.c b/trust/session.c
index b93a5c3..d464394 100644
--- a/trust/session.c
+++ b/trust/session.c
@@ -59,12 +59,18 @@ p11_session_new (p11_token *token)
session->handle = p11_module_next_id ();
session->builder = p11_builder_new (P11_BUILDER_FLAG_NONE);
- return_val_if_fail (session->builder, NULL);
+ if (session->builder == NULL) {
+ p11_session_free (session);
+ return_val_if_reached (NULL);
+ }
session->index = p11_index_new (p11_builder_build, NULL, NULL,
p11_builder_changed,
session->builder);
- return_val_if_fail (session->index != NULL, NULL);
+ if (session->index == NULL) {
+ p11_session_free (session);
+ return_val_if_reached (NULL);
+ }
session->token = token;
diff --git a/trust/token.c b/trust/token.c
index 4cbcc77..fd3b043 100644
--- a/trust/token.c
+++ b/trust/token.c
@@ -829,7 +829,10 @@ p11_token_new (CK_SLOT_ID slot,
return_val_if_fail (token != NULL, NULL);
token->builder = p11_builder_new (P11_BUILDER_FLAG_TOKEN);
- return_val_if_fail (token->builder != NULL, NULL);
+ if (token->builder == NULL) {
+ p11_token_free (token);
+ return_val_if_reached (NULL);
+ }
token->index = p11_index_new (on_index_build,
on_index_store,