DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maciej Gajdzica <maciejx.t.gajdzica@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 5/6] cfgfile: fixed calling free for each section in rte_cfgfile_close
Date: Wed, 17 Jun 2015 16:48:47 +0200	[thread overview]
Message-ID: <1434552528-3576-6-git-send-email-maciejx.t.gajdzica@intel.com> (raw)
In-Reply-To: <1434552528-3576-1-git-send-email-maciejx.t.gajdzica@intel.com>

From: Pawel Wodkowski <pawelx.wodkowski@intel.com>

Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
---
 lib/librte_cfgfile/rte_cfgfile.c |   53 +++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index 4e77ef5..2ce5d70 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -43,13 +43,13 @@
 
 struct rte_cfgfile_section {
 	char name[CFG_NAME_LEN];
-	int num_entries;
+	size_t num_entries;
 	struct rte_cfgfile_entry *entries[0];
 };
 
 struct rte_cfgfile {
 	int flags;
-	int num_sections;
+	size_t num_sections;
 	struct rte_cfgfile_section *sections[0];
 };
 
@@ -60,6 +60,15 @@ struct rte_cfgfile {
  * for new entries do we add in */
 #define CFG_ALLOC_ENTRY_BATCH 16
 
+/* Helpers */
+
+#define _skip_spaceses(str) ({  \
+	__typeof__(str) p = (str);  \
+	while (isspace(*p))         \
+		p++;                    \
+	p;                          \
+})
+
 static unsigned
 _strip(char *str, unsigned len)
 {
@@ -424,28 +433,26 @@ rte_cfgfile_load(const char *filename, int flags)
 	return cfg;
 }
 
-
-int rte_cfgfile_close(struct rte_cfgfile *cfg)
+int
+rte_cfgfile_close(struct rte_cfgfile *cfg)
 {
-	int i, j;
+	struct rte_cfgfile_section *s;
+	size_t i, j;
 
 	if (cfg == NULL)
 		return -1;
 
 	for (i = 0; i < cfg->num_sections; i++) {
-		if (cfg->sections[i] != NULL) {
-			if (cfg->sections[i]->num_entries) {
-				for (j = 0; j < cfg->sections[i]->num_entries;
-					j++) {
-					if (cfg->sections[i]->entries[j] !=
-						NULL)
-						free(cfg->sections[i]->
-							entries[j]);
-				}
-			}
-			free(cfg->sections[i]);
+		s = cfg->sections[i];
+		for (j = 0; j < s->num_entries; j++) {
+			free(cfg->sections[i]->entries[j]->value);
+			free(cfg->sections[i]->entries[j]);
 		}
+		free(cfg->sections[i]->entries);
+		free(s);
 	}
+
+	free(cfg->sections);
 	free(cfg);
 
 	return 0;
@@ -455,7 +462,7 @@ int
 rte_cfgfile_num_sections(struct rte_cfgfile *cfg, const char *sectionname,
 size_t length)
 {
-	int i;
+	size_t i;
 	int num_sections = 0;
 	for (i = 0; i < cfg->num_sections; i++) {
 		if (strncmp(cfg->sections[i]->name, sectionname, length) == 0)
@@ -468,9 +475,9 @@ int
 rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
 	int max_sections)
 {
-	int i;
+	size_t i;
 
-	for (i = 0; i < cfg->num_sections && i < max_sections; i++)
+	for (i = 0; i < cfg->num_sections && (int)i < max_sections; i++)
 		snprintf(sections[i], CFG_NAME_LEN, "%s",
 		cfg->sections[i]->name);
 
@@ -480,7 +487,7 @@ rte_cfgfile_sections(struct rte_cfgfile *cfg, char *sections[],
 static const struct rte_cfgfile_section *
 _get_section(struct rte_cfgfile *cfg, const char *sectionname)
 {
-	int i;
+	size_t i;
 	for (i = 0; i < cfg->num_sections; i++) {
 		if (strncmp(cfg->sections[i]->name, sectionname,
 				sizeof(cfg->sections[0]->name)) == 0)
@@ -510,11 +517,11 @@ int
 rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 		struct rte_cfgfile_entry *entries, int max_entries)
 {
-	int i;
+	size_t i;
 	const struct rte_cfgfile_section *sect = _get_section(cfg, sectionname);
 	if (sect == NULL)
 		return -1;
-	for (i = 0; i < max_entries && i < sect->num_entries; i++)
+	for (i = 0; (int)i < max_entries && i < sect->num_entries; i++)
 		entries[i] = *sect->entries[i];
 	return i;
 }
@@ -523,7 +530,7 @@ const char *
 rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname,
 		const char *entryname)
 {
-	int i;
+	size_t i;
 	const struct rte_cfgfile_section *sect = _get_section(cfg, sectionname);
 	if (sect == NULL)
 		return NULL;
-- 
1.7.9.5

  parent reply	other threads:[~2015-06-17 15:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17 14:48 [dpdk-dev] [PATCH v2 0/6] cfgfile: config file parsing extension Maciej Gajdzica
2015-06-17 14:48 ` [dpdk-dev] [PATCH v2 1/6] librte_cfgfile: fix code formating in header file Maciej Gajdzica
2015-06-17 14:48 ` [dpdk-dev] [PATCH v2 2/6] librte_compat: fix macro definition Maciej Gajdzica
2015-06-17 14:48 ` [dpdk-dev] [PATCH v2 3/6] cfgfile: split rte_cfgfile_load to smaller functions Maciej Gajdzica
2015-06-17 14:48 ` [dpdk-dev] [PATCH v2 4/6] cfgfile: added line continue character '\' to make multiline values possible Maciej Gajdzica
2015-06-17 14:48 ` Maciej Gajdzica [this message]
2015-06-18 12:29   ` [dpdk-dev] [PATCH v2 5/6] cfgfile: fixed calling free for each section in rte_cfgfile_close Thomas Monjalon
2015-06-18 13:08     ` Gajdzica, MaciejX T
2015-06-17 14:48 ` [dpdk-dev] [PATCH v2 6/6] cfgfile: added new implementation of section parsing Maciej Gajdzica
2015-06-18 12:37   ` Thomas Monjalon
2015-06-18 13:09     ` Gajdzica, MaciejX T
2015-06-17 16:51 ` [dpdk-dev] [PATCH v2 0/6] cfgfile: config file parsing extension Dumitrescu, Cristian
2015-06-18 12:44 ` Thomas Monjalon
2015-06-22 14:58 ` Gajdzica, MaciejX T

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=1434552528-3576-6-git-send-email-maciejx.t.gajdzica@intel.com \
    --to=maciejx.t.gajdzica@intel.com \
    --cc=dev@dpdk.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).