Linux NFS development
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: "J. Bruce Fields" <bfields@redhat.com>,
	Steve Dickson <SteveD@redhat.com>
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 07/15] conffile: free image of config file after parsing
Date: Fri, 02 Dec 2016 14:58:29 +1100	[thread overview]
Message-ID: <148065110911.28046.15239417720166462424.stgit@noble> (raw)
In-Reply-To: <148065078775.28046.5506130555300891075.stgit@noble>

conffile allocates memory and reads in the config file.
It then parses the file, using strdup() to take a copy of
any string that it uses, so after conf_parse() there are no
references in to the allocated file image.

conffile does not free this image.  It keeps a pointer, but never uses
it in an interesing way, and never frees it.  This is a little clumsy
and interfers with a future patch which will support the inclusion of
subordinate config files.

So free 'new_conf_addr' when finished with it, and discard the
'conf_addr' variable that stored it.
This has an insignificant performance consequence in that we node
always free everything in the hash table, even when we know it must
be empty.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 support/nfs/conffile.c |   17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index 609d78294f35..e4597507b922 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -107,8 +107,6 @@ struct conf_binding {
 char *conf_path;
 LIST_HEAD (conf_bindings, conf_binding) conf_bindings[256];
 
-static char *conf_addr;
-
 static __inline__ uint8_t
 conf_hash(char *s)
 {
@@ -396,7 +394,7 @@ conf_reinit(void)
 		/* XXX I assume short reads won't happen here.  */
 		if (read (fd, new_conf_addr, sz) != (int)sz) {
 			xlog_warn("conf_reinit: read (%d, %p, %lu) failed",
-   				fd, new_conf_addr, (unsigned long)sz);
+				fd, new_conf_addr, (unsigned long)sz);
 			goto fail;
 		}
 		close(fd);
@@ -404,6 +402,7 @@ conf_reinit(void)
 		trans = conf_begin();
 		/* XXX Should we not care about errors and rollback?  */
 		conf_parse(trans, new_conf_addr, sz);
+		free(new_conf_addr);
 	}
 	else
 		trans = conf_begin();
@@ -412,17 +411,13 @@ conf_reinit(void)
 	conf_load_defaults();
 
 	/* Free potential existing configuration.  */
-	if (conf_addr) {
-		for (i = 0; i < sizeof conf_bindings / sizeof conf_bindings[0]; i++) {
-			cb = LIST_FIRST (&conf_bindings[i]);
-			for (; cb; cb = LIST_FIRST (&conf_bindings[i]))
-				conf_remove_now(cb->section, cb->tag);
-		}
-		free (conf_addr);
+	for (i = 0; i < sizeof conf_bindings / sizeof conf_bindings[0]; i++) {
+		cb = LIST_FIRST (&conf_bindings[i]);
+		for (; cb; cb = LIST_FIRST (&conf_bindings[i]))
+			conf_remove_now(cb->section, cb->tag);
 	}
 
 	conf_end(trans, 1);
-	conf_addr = new_conf_addr;
 	return;
 
 fail:



  parent reply	other threads:[~2016-12-02  3:59 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  3:58 [RFC PATCH 00/15] Enhance /etc/nfs.conf usage and remove nfs-config.service NeilBrown
2016-12-02  3:58 ` [PATCH 05/15] Add /etc/nfs.conf support for statd NeilBrown
2016-12-02  3:58 ` [PATCH 01/15] Add man-page describing /etc/nfs.conf NeilBrown
2016-12-02  3:58 ` [PATCH 04/15] Add /etc/nfs.conf support for mountd NeilBrown
2016-12-02  3:58 ` [PATCH 02/15] conffile: add bool support NeilBrown
2016-12-02  3:58 ` [PATCH 03/15] Add /etc/nfs.conf support to rpc.nfsd NeilBrown
2016-12-05 22:27   ` J. Bruce Fields
2016-12-05 22:42     ` NeilBrown
2016-12-06 17:52   ` Steve Dickson
2016-12-06 22:30     ` NeilBrown
2016-12-07 14:34       ` Steve Dickson
2016-12-06 18:51   ` Steve Dickson
2016-12-06 22:36     ` NeilBrown
2016-12-07 14:44       ` Steve Dickson
2016-12-07 18:08         ` J. Bruce Fields
2016-12-07 23:14           ` NeilBrown
2016-12-08  0:38             ` Steve Dickson
2016-12-09 22:43             ` J. Bruce Fields
2016-12-20 23:22       ` NeilBrown
2016-12-21  1:55         ` J. Bruce Fields
2016-12-02  3:58 ` [PATCH 09/15] conffile: add support for include files NeilBrown
2016-12-02  3:58 ` NeilBrown [this message]
2016-12-02  3:58 ` [PATCH 10/15] conffile: strip "quotes" from values in conf file NeilBrown
2016-12-02  3:58 ` [PATCH 11/15] conffile: ignore setting of empty string NeilBrown
2016-12-02  3:58 ` [PATCH 06/15] Add /etc/nfs.conf support for sm-notify NeilBrown
2016-12-02  3:58 ` [PATCH 08/15] conffile: split loading of file into a separate function NeilBrown
2016-12-02  3:58 ` [PATCH 15/15] Add nfs.systemd man page NeilBrown
2016-12-02  3:58 ` [PATCH 12/15] conffile: allow $name expansion of tag values NeilBrown
2016-12-02  3:58 ` [PATCH 13/15] statd: allow --no-notify to be passed via environment variable NeilBrown
2016-12-02  3:58 ` [PATCH 14/15] systemd: Remove the nfs-config.service NeilBrown
2016-12-02 15:56 ` [RFC PATCH 00/15] Enhance /etc/nfs.conf usage and remove nfs-config.service J. Bruce Fields
2016-12-06 16:55 ` Steve Dickson
2016-12-06 22:38   ` NeilBrown
2016-12-07 14:24     ` Steve Dickson
2016-12-06 17:26 ` J. Bruce Fields
2016-12-06 22:47   ` NeilBrown
2016-12-07 14:19     ` J. Bruce Fields
2016-12-06 19:25 ` Steve Dickson
2016-12-06 22:51   ` NeilBrown
2016-12-07 14:21     ` Steve Dickson
2016-12-20 18:33 ` Steve Dickson

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=148065110911.28046.15239417720166462424.stgit@noble \
    --to=neilb@suse.com \
    --cc=SteveD@redhat.com \
    --cc=bfields@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