summaryrefslogtreecommitdiff
path: root/src/settings.c
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/settings.c
parent9e56788affedd6b01df6764732a4ba786f7a47f3 (diff)
fb,settings: return NULL from _free() methods
and ignore NULL parameters as benign
Diffstat (limited to 'src/settings.c')
-rw-r--r--src/settings.c53
1 files changed, 28 insertions, 25 deletions
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;
}
© All Rights Reserved