summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <jbj>2016-06-24 19:04:19 +0000
committerjbj <jbj>2016-06-24 19:04:19 +0000
commit9348ab09e1a92df2e248e416d1161d01a97ed2bb (patch)
tree00b836033e3c8b70a469285d3ceff2585e8d9512
parent935f3f1b474c8f386b8de4e2b1a04909b9bc91d8 (diff)
downloadlibpopt-9348ab09e1a92df2e248e416d1161d01a97ed2bb.tar.gz
- use poptArgvFree to avoid memory leaks.
-rw-r--r--CHANGES1
-rw-r--r--libpopt.vers1
-rw-r--r--popt.c7
-rw-r--r--popt.h9
-rw-r--r--poptparse.c2
5 files changed, 11 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 4c01aed..7a81d82 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,5 @@
1.17 -> 2.0:
+ - jbj: use poptArgvFree to avoid memory leaks.
- jbj: i18n: update PO files (Translation Project).
- jbj: i18n: update PO files (Translation Project).
- jbj: i18n: update da fr nb nl uk, and msgmerge (Translation Project).
diff --git a/libpopt.vers b/libpopt.vers
index 3ac5e52..b736801 100644
--- a/libpopt.vers
+++ b/libpopt.vers
@@ -8,6 +8,7 @@ LIBPOPT_0
poptAddAlias;
poptAddItem;
poptAliasOptions;
+ poptArgvFree;
poptBadOption;
_poptBitsN;
_poptBitsM;
diff --git a/popt.c b/popt.c
index cff60b7..c536a17 100644
--- a/popt.c
+++ b/popt.c
@@ -1770,12 +1770,7 @@ poptItem poptFreeItems(/*@only@*/ /*@null@*/ poptItem items, int nitems)
if (items != NULL) {
poptItem item = items;
while (--nitems >= 0) {
-#if !defined(SUPPORT_CONTIGUOUS_ARGV)
- int i;
- for (i = 0; item->argv[i]; i++)
- item->argv[i] = _free(item->argv[i]);
-#endif
- item->argv = _free(item->argv);
+ item->argv = poptArgvFree(item->argv);
/*@-modobserver -observertrans -dependenttrans@*/
item->option.longName = _free(item->option.longName);
item->option.descrip = _free(item->option.descrip);
diff --git a/popt.h b/popt.h
index 6489fa7..b123272 100644
--- a/popt.h
+++ b/popt.h
@@ -470,8 +470,6 @@ int poptDupArgv(int argc, /*@null@*/ const char **argv,
* Parse a string into an argument array.
* The parse allows ', ", and \ quoting, but ' is treated the same as " and
* both may include \ quotes.
- * @note: The argument array is malloc'd as a single area, so only argv must
- * be free'd.
*
* @param s string to parse
* @retval argcPtr address of returned no. of arguments
@@ -482,6 +480,13 @@ int poptParseArgvString(const char * s,
/*@modifies *argcPtr, *argvPtr @*/;
/** \ingroup popt
+ * Free the argument array.
+ * @param argv argument array.
+ * @retval NULL always
+ */
+const char ** poptArgvFree(const char ** argv);
+
+/** \ingroup popt
* Parses an input configuration file and returns an string that is a
* command line. For use with popt. You must free the return value when done.
*
diff --git a/poptparse.c b/poptparse.c
index 819d30b..6c3fa73 100644
--- a/poptparse.c
+++ b/poptparse.c
@@ -16,7 +16,7 @@
#define assert(_x)
#endif
-static const char ** poptArgvFree(/*@only@*/ const char ** av)
+const char ** poptArgvFree(/*@only@*/ const char ** av)
{
#if !defined(SUPPORT_CONTIGUOUS_ARGV)
if (av) {