summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-02-17 11:07:45 -0800
committerVito Caputo <vcaputo@pengaru.com>2021-02-17 11:07:45 -0800
commit55db80c6970b8643b4777c3b5586531e2d2e7469 (patch)
treeab4178a33ebc1c8d77ec6669a6c0d433574257c8 /src
parent9e56788affedd6b01df6764732a4ba786f7a47f3 (diff)
fb,settings: return NULL from _free() methods
and ignore NULL parameters as benign
Diffstat (limited to 'src')
-rw-r--r--src/fb.c26
-rw-r--r--src/fb.h2
-rw-r--r--src/settings.c53
-rw-r--r--src/settings.h4
4 files changed, 46 insertions, 39 deletions
diff --git a/src/fb.c b/src/fb.c
index 03a04ac..f24e4fe 100644
--- a/src/fb.c
+++ b/src/fb.c
@@ -239,22 +239,26 @@ void fb_get_put_pages_count(fb_t *fb, unsigned *count)
/* free the fb and associated resources */
-void fb_free(fb_t *fb)
+fb_t * fb_free(fb_t *fb)
{
- if (fb->active_page)
- fb_release(fb);
+ if (fb) {
+ if (fb->active_page)
+ fb_release(fb);
- /* TODO: free all the pages */
+ /* TODO: free all the pages */
- if (fb->ops->shutdown && fb->ops_context)
- fb->ops->shutdown(fb, fb->ops_context);
+ if (fb->ops->shutdown && fb->ops_context)
+ fb->ops->shutdown(fb, fb->ops_context);
- pthread_mutex_destroy(&fb->ready_mutex);
- pthread_cond_destroy(&fb->ready_cond);
- pthread_mutex_destroy(&fb->inactive_mutex);
- pthread_cond_destroy(&fb->inactive_cond);
+ pthread_mutex_destroy(&fb->ready_mutex);
+ pthread_cond_destroy(&fb->ready_cond);
+ pthread_mutex_destroy(&fb->inactive_mutex);
+ pthread_cond_destroy(&fb->inactive_cond);
- free(fb);
+ free(fb);
+ }
+
+ return NULL;
}
diff --git a/src/fb.h b/src/fb.h
index 3a3646a..5e1331e 100644
--- a/src/fb.h
+++ b/src/fb.h
@@ -47,7 +47,7 @@ typedef struct fb_ops_t {
fb_page_t * fb_page_get(fb_t *fb);
void fb_page_put(fb_t *fb, fb_page_t *page);
-void fb_free(fb_t *fb);
+fb_t * fb_free(fb_t *fb);
void fb_get_put_pages_count(fb_t *fb, unsigned *count);
int fb_new(const fb_ops_t *ops, settings_t *settings, int n_pages, fb_t **res_fb);
void * fb_context(fb_t *fb);
diff --git a/src/settings.c b/src/settings.c
index 3ba4f15..e54a690 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -119,20 +119,21 @@ settings_t * settings_new(const char *settings_string)
/* free structure attained via settings_new() */
-void settings_free(settings_t *settings)
+settings_t * settings_free(settings_t *settings)
{
- unsigned i;
- assert(settings);
+ if (settings) {
+ for (unsigned i = 0; i < settings->num; i++) {
+ free((void *)settings->keys[i]);
+ free((void *)settings->values[i]);
+ }
- for (i = 0; i < settings->num; i++) {
- free((void *)settings->keys[i]);
- free((void *)settings->values[i]);
+ free((void *)settings->keys);
+ free((void *)settings->values);
+ free(settings);
}
- free((void *)settings->keys);
- free((void *)settings->values);
- free(settings);
+ return NULL;
}
@@ -282,28 +283,30 @@ int setting_desc_clone(const setting_desc_t *desc, setting_desc_t **res_desc)
}
-void setting_desc_free(setting_desc_t *desc)
+setting_desc_t * setting_desc_free(setting_desc_t *desc)
{
- free((void *)desc->name);
- free((void *)desc->key);
- free((void *)desc->regex);
- free((void *)desc->preferred);
-
- if (desc->values) {
- unsigned i;
-
- for (i = 0; desc->values[i]; i++) {
- free((void *)desc->values[i]);
+ if (desc) {
+ free((void *)desc->name);
+ free((void *)desc->key);
+ free((void *)desc->regex);
+ free((void *)desc->preferred);
+
+ if (desc->values) {
+ for (unsigned i = 0; desc->values[i]; i++) {
+ free((void *)desc->values[i]);
+
+ if (desc->annotations)
+ free((void *)desc->annotations[i]);
+ }
- if (desc->annotations)
- free((void *)desc->annotations[i]);
+ free((void *)desc->values);
+ free((void *)desc->annotations);
}
- free((void *)desc->values);
- free((void *)desc->annotations);
+ free(desc);
}
- free(desc);
+ return NULL;
}
diff --git a/src/settings.h b/src/settings.h
index c538531..9916ebb 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -24,7 +24,7 @@ typedef struct setting_desc_generator_t {
typedef struct settings_t settings_t;
settings_t * settings_new(const char *settings);
-void settings_free(settings_t *settings);
+settings_t * settings_free(settings_t *settings);
const char * settings_get_value(const settings_t *settings, const char *key);
const char * settings_get_key(const settings_t *settings, unsigned pos);
int settings_add_value(settings_t *settings, const char *key, const char *value);
@@ -32,7 +32,7 @@ char * settings_as_arg(const settings_t *settings);
int settings_apply_desc_generators(const settings_t *settings, const setting_desc_generator_t generators[], unsigned n_generators, void *setup_context, setting_desc_t **next_setting);
int setting_desc_clone(const setting_desc_t *desc, setting_desc_t **res_desc);
-void setting_desc_free(setting_desc_t *desc);
+setting_desc_t * setting_desc_free(setting_desc_t *desc);
int setting_desc_check(const setting_desc_t *desc, const char *value);
#ifndef SETTINGS_STR
© All Rights Reserved