From: Justin Mitchell <jumitche@redhat.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Cc: Steve Dickson <SteveD@RedHat.com>
Subject: [PATCH v2 1/7] nfs-utils: Fix minor memory leaks
Date: Thu, 03 May 2018 17:47:19 +0100 [thread overview]
Message-ID: <1525366039.7550.19.camel@redhat.com> (raw)
In-Reply-To: <1525365943.7550.18.camel@redhat.com>
Fix some minor memory leaks, typos, and trailing whitespace
Signed-off-by: Justin Mitchell <jumitche@redhat.com>
---
support/nfs/conffile.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index 29f132d..28e29b7 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -57,9 +57,9 @@
static void conf_load_defaults(void);
static char * conf_readfile(const char *path);
-static int conf_set(int , const char *, const char *, const char *,
+static int conf_set(int , const char *, const char *, const char *,
const char *, int , int );
-static void conf_parse(int trans, char *buf,
+static void conf_parse(int trans, char *buf,
char **section, char **subsection);
struct conf_trans {
@@ -177,7 +177,7 @@ conf_remove_section_now(const char *section)
* into SECTION of our configuration database.
*/
static int
-conf_set_now(const char *section, const char *arg, const char *tag,
+conf_set_now(const char *section, const char *arg, const char *tag,
const char *value, int override, int is_default)
{
struct conf_binding *node = 0;
@@ -186,7 +186,7 @@ conf_set_now(const char *section, const char *arg, const char *tag,
conf_remove_now(section, tag);
else if (conf_get_section(section, arg, tag)) {
if (!is_default) {
- xlog(LOG_INFO, "conf_set: duplicate tag [%s]:%s, ignoring...\n",
+ xlog(LOG_INFO, "conf_set: duplicate tag [%s]:%s, ignoring...",
section, tag);
}
return 1;
@@ -220,7 +220,7 @@ conf_parse_line(int trans, char *line, int lineno, char **section, char **subsec
return;
/* Strip off any leading blanks */
- while (isblank(*line))
+ while (isblank(*line))
line++;
/* Lines starting with '#' or ';' are comments. */
@@ -241,7 +241,7 @@ conf_parse_line(int trans, char *line, int lineno, char **section, char **subsec
}
/* Strip off any blanks after '[' */
- while (isblank(*line))
+ while (isblank(*line))
line++;
/* find the closing ] */
@@ -256,7 +256,7 @@ conf_parse_line(int trans, char *line, int lineno, char **section, char **subsec
*(ptr--) = '\0';
/* Strip off any blanks before ']' */
- while (ptr >= line && isblank(*ptr))
+ while (ptr >= line && isblank(*ptr))
*(ptr--)='\0';
/* look for an arg to split from the section name */
@@ -289,7 +289,7 @@ conf_parse_line(int trans, char *line, int lineno, char **section, char **subsec
}
*ptr = '\0';
*subsection = strdup(val);
- if (!*subsection)
+ if (!*subsection)
xlog_warn("conf_parse_line: %d: malloc arg failed", lineno);
return;
}
@@ -535,8 +535,8 @@ conf_init_file(const char *conf_file)
conf_load_file(conf_file);
}
-/*
- * Empty the config and free up any used memory
+/*
+ * Empty the config and free up any used memory
*/
void
conf_cleanup(void)
@@ -618,7 +618,7 @@ conf_match_num(const char *section, const char *tag, int x)
xlog(LOG_INFO, "conf_match_num: %s:%s %d==%d?", section, tag, val, x);
return x == val;
case 3:
- xlog(LOG_INFO, "conf_match_num: %s:%s %d<=%d<=%d?", section,
+ xlog(LOG_INFO, "conf_match_num: %s:%s %d<=%d<=%d?", section,
tag, min, x, max);
return min <= x && max >= x;
default:
@@ -642,7 +642,7 @@ char *
conf_get_str_with_def(const char *section, const char *tag, char *def)
{
char * result = conf_get_section(section, NULL, tag);
- if (!result)
+ if (!result)
return def;
return result;
}
@@ -659,7 +659,7 @@ retry:
for (; cb; cb = LIST_NEXT (cb, link)) {
if (strcasecmp(section, cb->section) != 0)
continue;
- if (arg && strcasecmp(arg, cb->arg) != 0)
+ if (arg && (cb->arg == NULL || strcasecmp(arg, cb->arg) != 0))
continue;
if (strcasecmp(tag, cb->tag) != 0)
continue;
@@ -917,6 +917,8 @@ conf_set(int transaction, const char *section, const char *arg,
fail:
if (node->tag)
free(node->tag);
+ if (node->arg)
+ free(node->arg);
if (node->section)
free(node->section);
if (node)
@@ -987,8 +989,8 @@ conf_end(int transaction, int commit)
if (commit) {
switch (node->op) {
case CONF_SET:
- conf_set_now(node->section, node->arg,
- node->tag, node->value, node->override,
+ conf_set_now(node->section, node->arg,
+ node->tag, node->value, node->override,
node->is_default);
break;
case CONF_REMOVE:
@@ -1004,6 +1006,8 @@ conf_end(int transaction, int commit)
TAILQ_REMOVE (&conf_trans_queue, node, link);
if (node->section)
free(node->section);
+ if (node->arg)
+ free(node->arg);
if (node->tag)
free(node->tag);
if (node->value)
@@ -1066,7 +1070,7 @@ conf_report (void)
diff_arg = 1;
}
/* Dump this entry. */
- if (!current_section || strcmp(cb->section, current_section)
+ if (!current_section || strcmp(cb->section, current_section)
|| diff_arg) {
if (current_section || diff_arg) {
len = strlen (current_section) + 3;
@@ -1077,19 +1081,19 @@ conf_report (void)
goto mem_fail;
if (current_arg)
- snprintf(dnode->s, len, "[%s \"%s\"]",
+ snprintf(dnode->s, len, "[%s \"%s\"]",
current_section, current_arg);
else
snprintf(dnode->s, len, "[%s]", current_section);
- dnode->next =
+ dnode->next =
(struct dumper *)calloc(1, sizeof (struct dumper));
dnode = dnode->next;
if (!dnode)
goto mem_fail;
dnode->s = "";
- dnode->next =
+ dnode->next =
(struct dumper *)calloc(1, sizeof (struct dumper));
dnode = dnode->next;
if (!dnode)
--
1.8.3.1
next prev parent reply other threads:[~2018-05-03 16:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-03 16:45 [PATCH v2 0/7] nfs-utils: nfsconf cli tool and code tests Justin Mitchell
2018-05-03 16:47 ` Justin Mitchell [this message]
2018-05-03 16:48 ` [PATCH v2 2/7] nfs-utils: Make config includes relative to current config Justin Mitchell
2018-05-03 16:48 ` [PATCH v2 3/7] nfs-utils: Use config file name in error messages Justin Mitchell
2018-05-03 16:49 ` [PATCH v2 4/7] nfs-utils: Indicate if config file was missing Justin Mitchell
2018-05-03 16:50 ` [PATCH v2 5/7] nfs-utils: tidy up output of conf_report Justin Mitchell
2018-05-03 16:50 ` [PATCH v2 6/7] nfs-utils: Add nfsconftool cli Justin Mitchell
2018-05-03 16:51 ` [PATCH v2 7/7] nfs-utils: use nfsconftool cli to test library function Justin Mitchell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1525366039.7550.19.camel@redhat.com \
--to=jumitche@redhat.com \
--cc=SteveD@RedHat.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).