From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 22826C4B0 for ; Wed, 17 Jun 2015 17:10:23 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 17 Jun 2015 08:10:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,633,1427785200"; d="scan'208";a="748397832" Received: from unknown (HELO stargo) ([10.217.248.233]) by orsmga002.jf.intel.com with SMTP; 17 Jun 2015 08:10:01 -0700 Received: by stargo (sSMTP sendmail emulation); Wed, 17 Jun 2015 17:08:38 +0200 From: Maciej Gajdzica To: dev@dpdk.org Date: Wed, 17 Jun 2015 16:48:47 +0200 Message-Id: <1434552528-3576-6-git-send-email-maciejx.t.gajdzica@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1434552528-3576-1-git-send-email-maciejx.t.gajdzica@intel.com> References: <1434552528-3576-1-git-send-email-maciejx.t.gajdzica@intel.com> Subject: [dpdk-dev] [PATCH v2 5/6] cfgfile: fixed calling free for each section in rte_cfgfile_close X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2015 15:10:24 -0000 From: Pawel Wodkowski Signed-off-by: Pawel Wodkowski --- 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