summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjbj <jbj>2011-04-19 23:30:03 +0000
committerjbj <jbj>2011-04-19 23:30:03 +0000
commit18138c81c7761e5660513b57db336afae7b145ad (patch)
tree81cd0e707cc8f50276ce33beb6e8bb4b1b9f6e1a
parent69129313616c67c759953ba2bd15c289b983c2ce (diff)
downloadlibpopt-18138c81c7761e5660513b57db336afae7b145ad.tar.gz
- fix: plug another memory leak related to contiguous argv malloc.rpm-5_3_10-release
-rw-r--r--CHANGES2
-rw-r--r--popt.c16
-rw-r--r--poptconfig.c2
-rw-r--r--poptparse.c11
4 files changed, 23 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 02bdf26..bba23c8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,6 @@
1.17 -> 2.0:
+ - jbj: fix: plug another memory leak related to contiguous argv malloc.
+ - jbj: fix: plug a memory leak related to contiguous argv malloc.
- devzero2000: fix the configmake.h make rule: update its timestamp also if it don't change.
- devzero2000: revert bad commit: add missing glob.h and fnmatch.h in configure.ac, add struct sb in poptconfig.c
- devzero2000: Rewrite the logic in poptReadDefaultConfig
diff --git a/popt.c b/popt.c
index 189a01f..870b1f9 100644
--- a/popt.c
+++ b/popt.c
@@ -234,9 +234,14 @@ static void cleanOSE(/*@special@*/ struct optionStackEntry *os)
/*@releases os->nextArg, os->argv, os->argb @*/
/*@modifies os @*/
{
- os->nextArg = _free(os->nextArg);
+#if !defined(SUPPORT_CONTIGUOUS_ARGV)
+ int i;
+ for (i = 0; os->argv[i]; i++)
+ os->argv[i] = _free(os->argv[i]);
+#endif
os->argv = _free(os->argv);
os->argb = PBM_FREE(os->argb);
+ os->nextArg = _free(os->nextArg);
}
void poptResetContext(poptContext con)
@@ -1750,12 +1755,17 @@ poptItem poptFreeItems(/*@only@*/ /*@null@*/ poptItem items, int nitems)
{
if (items != NULL) {
poptItem item = items;
+ int i;
while (--nitems >= 0) {
/*@-modobserver -observertrans -dependenttrans@*/
item->option.longName = _free(item->option.longName);
item->option.descrip = _free(item->option.descrip);
item->option.argDescrip = _free(item->option.argDescrip);
/*@=modobserver =observertrans =dependenttrans@*/
+#if !defined(SUPPORT_CONTIGUOUS_ARGV)
+ for (i = 0; item->argv[i]; i++)
+ item->argv[i] = _free(item->argv[i]);
+#endif
item->argv = _free(item->argv);
item++;
}
@@ -1815,12 +1825,12 @@ int poptAddItem(poptContext con, poptItem newItem, int flags)
case 1:
items = &con->execs;
nitems = &con->numExecs;
- *items = (poptItem) xrealloc((*items), ((*nitems) + 1) * sizeof(**items));
+ *items = (poptItem) xrealloc(*items, ((*nitems) + 1) * sizeof(**items));
break;
case 0:
items = &con->aliases;
naliases = &con->numAliases;
- *items = (poptItem) xrealloc((*items), ((*naliases) + 1) * sizeof(**items));
+ *items = (poptItem) xrealloc(*items, ((*naliases) + 1) * sizeof(**items));
break;
default:
return 1;
diff --git a/poptconfig.c b/poptconfig.c
index bb07b8d..2355976 100644
--- a/poptconfig.c
+++ b/poptconfig.c
@@ -381,7 +381,7 @@ static int poptConfigLine(poptContext con, char * line)
/*@=nullstate@*/
exit:
rc = 0; /* XXX for now, always return success */
- b=_free(b);
+ b = _free(b);
return rc;
}
/*@=compmempass@*/
diff --git a/poptparse.c b/poptparse.c
index 8f8d978..485b875 100644
--- a/poptparse.c
+++ b/poptparse.c
@@ -50,7 +50,7 @@ int poptDupArgv(int argc, const char **argv,
}
#endif
- dst = (char*) xmalloc(nb);
+ dst = (char *) xmalloc(nb);
assert(dst); /* XXX can't happen */
if (dst == NULL)
return POPT_ERROR_MALLOC;
@@ -90,17 +90,19 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr)
size_t ns = strlen(s);
char * t = NULL;
char * te;
+ int i;
int rc = POPT_ERROR_MALLOC;
assert(argv); /* XXX can't happen */
if (argv == NULL) return rc;
- te = t = (char*) xcalloc((size_t)1, ns + 1);
+ te = t = (char*) xmalloc(ns + 1);
assert(te); /* XXX can't happen */
if (te == NULL) {
argv = _free(argv);
return rc;
}
+ *te = '\0';
argv[argc] = te;
for (se = s; *se != '\0'; se++) {
@@ -118,13 +120,14 @@ assert(te); /* XXX can't happen */
*te++ = *se;
} else if (_isspaceptr(se)) {
if (*argv[argc] != '\0') {
- te++, argc++;
+ *te++ = '\0', argc++;
if (argc == argvAlloced) {
argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA;
argv = (const char**) xrealloc(argv, sizeof(*argv) * argvAlloced);
assert(argv); /* XXX can't happen */
if (argv == NULL) goto exit;
}
+ *te = '\0';
argv[argc] = te;
}
} else
@@ -147,7 +150,7 @@ assert(argv); /* XXX can't happen */
}
if (strlen(argv[argc])) {
- argc++, te++;
+ argc++, *te++ = '\0';
}
rc = poptDupArgv(argc, argv, argcPtr, argvPtr);