diff options
author | Daiki Ueno <dueno@redhat.com> | 2018-10-16 18:10:05 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2018-10-17 10:13:32 +0200 |
commit | b10dadce5a3c921149b2c9fe0dec614f8076ebda (patch) | |
tree | 1be6432a3cd602032c4c036bcfac4fea1b1f7158 | |
parent | c76197ddbbd0c29adc2bceff2ee9f740f71d134d (diff) |
build: Free memory before return{,_val}_if_* macros
-rw-r--r-- | p11-kit/iter.c | 5 | ||||
-rw-r--r-- | p11-kit/proxy.c | 10 | ||||
-rw-r--r-- | trust/asn1.c | 15 | ||||
-rw-r--r-- | trust/builder.c | 5 | ||||
-rw-r--r-- | trust/index.c | 10 | ||||
-rw-r--r-- | trust/persist.c | 5 | ||||
-rw-r--r-- | trust/save.c | 29 | ||||
-rw-r--r-- | trust/session.c | 10 | ||||
-rw-r--r-- | trust/token.c | 5 |
9 files changed, 77 insertions, 17 deletions
diff --git a/p11-kit/iter.c b/p11-kit/iter.c index 0e4ca6e..d1ffd91 100644 --- a/p11-kit/iter.c +++ b/p11-kit/iter.c @@ -157,7 +157,10 @@ p11_kit_iter_new (P11KitUri *uri, return_val_if_fail (iter != NULL, NULL); iter->modules = p11_array_new (NULL); - return_val_if_fail (iter->modules != NULL, NULL); + if (iter->modules == NULL) { + p11_kit_iter_free (iter); + return_val_if_reached (NULL); + } iter->want_writable = !!(behavior & P11_KIT_ITER_WANT_WRITABLE); iter->preload_results = !(behavior & P11_KIT_ITER_BUSY_SESSIONS); diff --git a/p11-kit/proxy.c b/p11-kit/proxy.c index b7fb63d..abe7935 100644 --- a/p11-kit/proxy.c +++ b/p11-kit/proxy.c @@ -267,7 +267,10 @@ proxy_create (Proxy **res, CK_FUNCTION_LIST **loaded, py->forkid = p11_forkid; py->inited = modules_dup (loaded); - return_val_if_fail (py->inited != NULL, CKR_HOST_MEMORY); + if (py->inited == NULL) { + proxy_free (py, 0); + return_val_if_reached (CKR_HOST_MEMORY); + } rv = p11_kit_modules_initialize (py->inited, NULL); @@ -320,7 +323,10 @@ proxy_create (Proxy **res, CK_FUNCTION_LIST **loaded, } py->sessions = p11_dict_new (p11_dict_ulongptr_hash, p11_dict_ulongptr_equal, NULL, free); - return_val_if_fail (py->sessions != NULL, CKR_HOST_MEMORY); + if (py->sessions == NULL) { + proxy_free (py, 1); + return_val_if_reached (CKR_HOST_MEMORY); + } py->refs = 1; *res = py; 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, |