Make it use %%autosetup -S git and fix a memory leak

Signed-off-by: Peter Jones <pjones@redhat.com>
This commit is contained in:
Peter Jones 2017-07-28 15:04:04 -04:00
parent 4292099c99
commit befacb44b0
7 changed files with 199 additions and 52 deletions

6
.gitignore vendored
View File

@ -1 +1,5 @@
/popt-1.??.tar.gz
/popt-*.tar
/popt-*.tar.*
/*/
/.build*.log
/*.rpm

View File

@ -1,3 +1,8 @@
From cac87554c89d55dd7c082ad4b234314e72d73a22 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 15:16:17 -0400
Subject: [PATCH 1/4] Update pkgconfig directory
Patch by Robert Scheck <robert@fedoraproject.org> for popt <= 1.16 which changes
$(pkgconfigdir) on 64 bit systems from /usr/lib/pkgconfig to /usr/lib64/pkgconfig.
Using $(libdir)/pkgconfig rather $(prefix)/lib/pkgconfig seems to be common when
@ -6,21 +11,16 @@ searching on the Internet. This patch however is not really compliant with Fedor
--with-pkgconfigdir or similar should be implemented.
This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0265.html
---
Makefile.am | 2 +-
Makefile.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
--- popt-1.16/Makefile.in 2010-05-04 22:55:59.000000000 +0200
+++ popt-1.16/Makefile.in.pkgconfig 2013-11-24 15:06:43.000000000 +0100
@@ -370,7 +370,7 @@
libpopt_la_SOURCES = popt.c poptparse.c poptconfig.c popthelp.c poptint.c
libpopt_la_LDFLAGS = -no-undefined @LTLIBINTL@ @LTLIBICONV@ \
$(am__append_1)
-pkgconfigdir = $(prefix)/lib/pkgconfig
+pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = popt.pc
man_MANS = popt.3
BUILT_SOURCES = popt.pc # popt.lcd
--- popt-1.16/Makefile.am 2010-05-04 22:55:54.000000000 +0200
+++ popt-1.16/Makefile.am.pkgconfig 2013-11-24 15:02:21.000000000 +0100
@@ -47,7 +47,7 @@
diff --git a/Makefile.am b/Makefile.am
index d7aec9e..8cc6220 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,7 +47,7 @@ usrlib_LTLIBRARIES = libpopt.la
libpopt_la_SOURCES = popt.c poptparse.c poptconfig.c popthelp.c poptint.c
libpopt_la_LDFLAGS = -no-undefined @LTLIBINTL@ @LTLIBICONV@
@ -29,3 +29,19 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0265.h
pkgconfig_DATA = popt.pc
if HAVE_LD_VERSION_SCRIPT
diff --git a/Makefile.in b/Makefile.in
index 2e6890d..c331e20 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -370,7 +370,7 @@ usrlib_LTLIBRARIES = libpopt.la
libpopt_la_SOURCES = popt.c poptparse.c poptconfig.c popthelp.c poptint.c
libpopt_la_LDFLAGS = -no-undefined @LTLIBINTL@ @LTLIBICONV@ \
$(am__append_1)
-pkgconfigdir = $(prefix)/lib/pkgconfig
+pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = popt.pc
man_MANS = popt.3
BUILT_SOURCES = popt.pc # popt.lcd
--
2.13.3

View File

@ -1,3 +1,9 @@
From 61cc5004fb8e14464ae0afcffc6e2ee852b45a41 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 15:17:22 -0400
Subject: [PATCH 2/4] kludge poptBadOption() to return value on exec alias
failure
Patch by Panu Matilainen <pmatilai@redhat.com> for popt <= 1.16 which kludges
poptBadOption() to return something semi-meaningful on exec alias fail:
@ -9,10 +15,16 @@ poptBadOption() to return something semi-meaningful on exec alias fail:
went wrong.
This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.html
---
popt.c | 19 +++++++++++++++----
poptint.h | 1 +
2 files changed, 16 insertions(+), 4 deletions(-)
--- popt-1.16/popt.c 2010-01-19 01:39:10.000000000 +0100
+++ popt-1.16/popt.c.execfail 2013-11-24 15:50:06.000000000 +0100
@@ -192,6 +192,7 @@
diff --git a/popt.c b/popt.c
index a1c38a5..1a53f40 100644
--- a/popt.c
+++ b/popt.c
@@ -192,6 +192,7 @@ poptContext poptGetContext(const char * name, int argc, const char ** argv,
con->flags = flags;
con->execs = NULL;
con->numExecs = 0;
@ -20,7 +32,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.h
con->finalArgvAlloced = argc * 2;
con->finalArgv = calloc( (size_t)con->finalArgvAlloced, sizeof(*con->finalArgv) );
con->execAbsolute = 1;
@@ -236,6 +237,7 @@
@@ -236,6 +237,7 @@ void poptResetContext(poptContext con)
con->nextLeftover = 0;
con->restLeftover = 0;
con->doExec = NULL;
@ -28,7 +40,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.h
if (con->finalArgv != NULL)
for (i = 0; i < con->finalArgvCount; i++) {
@@ -564,6 +566,7 @@
@@ -564,6 +566,7 @@ if (_popt_debug)
/*@-nullstate@*/
rc = execvp(argv[0], (char *const *)argv);
/*@=nullstate@*/
@ -36,14 +48,12 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.h
exit:
if (argv) {
@@ -1697,11 +1700,19 @@
@@ -1697,11 +1700,19 @@ int poptAddItem(poptContext con, poptItem newItem, int flags)
const char * poptBadOption(poptContext con, unsigned int flags)
{
struct optionStackEntry * os = NULL;
+ const char *badOpt = NULL;
- if (con != NULL)
- os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
+
+ if (con != NULL) {
+ /* Stupid hack to return something semi-meaningful from exec failure */
+ if (con->execFail) {
@ -54,14 +64,19 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.h
+ }
+ }
- if (con != NULL)
- os = (flags & POPT_BADOPTION_NOALIAS) ? con->optionStack : con->os;
-
- return (os != NULL && os->argv != NULL ? os->argv[os->next - 1] : NULL);
+ return badOpt;
}
const char * poptStrerror(const int error)
--- popt-1.16/poptint.h 2010-01-19 01:39:10.000000000 +0100
+++ popt-1.16/poptint.h.execfail 2013-11-24 15:50:38.000000000 +0100
@@ -132,6 +132,7 @@
diff --git a/poptint.h b/poptint.h
index 80cbaca..0fcb26e 100644
--- a/poptint.h
+++ b/poptint.h
@@ -132,6 +132,7 @@ struct poptContext_s {
/*@owned@*/ /*@null@*/
poptItem execs;
int numExecs;
@ -69,3 +84,6 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0264.h
/*@only@*/ /*@null@*/
poptArgv finalArgv;
int finalArgvCount;
--
2.13.3

View File

@ -1,3 +1,8 @@
From abc7cc36f265e2fff199eca94e8cbf1cd0a28ab5 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 15:18:15 -0400
Subject: [PATCH 3/4] Fix some spelling mistakes in the man page.
Patch by John Bradshaw <john@johnbradshaw.org> for popt <= 1.16 which fixes some
spelling mistakes in popt man page.
@ -7,10 +12,15 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0263.h
Upstream already corrected some issues with http://rpm5.org/cvs/chngview?cn=16879
and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus popt
1.17 should make this patch completely obsolete.
---
popt.3 | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
--- popt-1.16/popt.3 2009-07-25 20:52:36.000000000 +0200
+++ popt-1.16/popt.3.man-page 2013-11-24 15:59:58.000000000 +0100
@@ -200,7 +200,7 @@
diff --git a/popt.3 b/popt.3
index 5d5a556..ca64a92 100644
--- a/popt.3
+++ b/popt.3
@@ -200,7 +200,7 @@ arguments.
.RB "This macro includes another option table (via " POPT_ARG_INCLUDE_TABLE
; see below) in the main one which provides the table entries for these
.RB "arguments. When " --usage " or " --help " are passed to programs which
@ -19,7 +29,7 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
stderr as soon as it finds the option, and exits the program with a
return code of 0. If you want to use popt's automatic help generation in
a different way, you need to explicitly add the option entries to your programs
@@ -210,7 +210,7 @@
@@ -210,7 +210,7 @@ If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_DOC_HIDDEN\fR,
the argument will not be shown in help output.
.sp
If the \fIargInfo\fR value is bitwise or'd with \fBPOPT_ARGFLAG_SHOW_DEFAULT\fR,
@ -28,7 +38,7 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
.sp
The final structure in the table should have all the pointer values set
.RB "to " NULL " and all the arithmetic values set to 0, marking the "
@@ -233,7 +233,7 @@
@@ -233,7 +233,7 @@ automatic help generation is being used, the \fIdescrip\fR field should
contain a overall description of the option table being included.
.sp
The other special option table entry type tells popt to call a function (a
@ -37,7 +47,7 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
when included option tables are being used, as the program which provides
the top-level option table doesn't need to be aware of the other options
which are provided by the included table. When a callback is set for
@@ -473,7 +473,7 @@
@@ -473,7 +473,7 @@ A parsed string has a quotation mismatch (such as a single quotation
.TP
.B POPT_ERROR_BADNUMBER
A conversion from a string to a number (int or long) failed due
@ -46,7 +56,7 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
.BR poptGetNextOpt() " is processing an argument of type "
.BR POPT_ARG_INT ", " POPT_ARG_SHORT ", " POPT_ARG_LONG ", " POPT_ARG_LONGLONG ", "
.RB POPT_ARG_FLOAT ", or " POPT_ARG_DOUBLE "."
@@ -517,7 +517,7 @@
@@ -517,7 +517,7 @@ These two functions make popt error handling trivial for most
applications. When an error is detected from most of the functions,
an error message is printed along with the error string from
.BR poptStrerror() ". When an error occurs during argument parsing, "
@ -55,7 +65,7 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
.sp
.nf
fprintf(stderr, "%s: %s\\n",
@@ -608,7 +608,7 @@
@@ -608,7 +608,7 @@ Although popt is usually used for parsing arguments already divided into
.RI "an " argv "-style array, some programs need to parse strings that "
are formatted identically to command lines. To facilitate this, popt
provides a function that parses a string into an array of strings,
@ -64,3 +74,6 @@ and solved the last ones with http://rpm5.org/cvs/chngview?cn=17375 now. Thus po
.sp
.nf
.B "#include <popt.h>"
--
2.13.3

View File

@ -1,3 +1,11 @@
From 1d86877a865338e554aa2480f021da517a86954f Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 15:18:46 -0400
Subject: [PATCH 4/4] Make --help and --usage translatable.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Patch initially by Miloslav Trmač <mitr@redhat.com> and revised by Akira Tagoh
<tagoh@redhat.com> for popt <= 1.16 which fixes the problem that help messages
for --help and --usage seem not translatable. There already was some i18n support
@ -6,10 +14,15 @@ for autohelp in popt.c, but not in popthelp.c, where it actually matters.
See https://bugzilla.redhat.com/show_bug.cgi?id=734434 for further details, please.
This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.html
---
popthelp.c | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
--- popt-1.16/popthelp.c 2009-08-28 09:06:33.000000000 +0900
+++ popt-1.16/popthelp.c.help 2014-01-08 12:04:00.888260244 +0900
@@ -89,7 +89,7 @@ static struct poptOption poptHelpOptions
diff --git a/popthelp.c b/popthelp.c
index 4859980..008fb2b 100644
--- a/popthelp.c
+++ b/popthelp.c
@@ -89,7 +89,7 @@ static struct poptOption poptHelpOptions2[] = {
{ "defaults", '\0', POPT_ARG_NONE, &show_option_defaults, 0,
N_("Display option defaults in message"), NULL },
#endif
@ -18,7 +31,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.h
POPT_TABLEEND
} ;
@@ -527,8 +527,11 @@ static size_t maxArgWidth(const struct p
@@ -527,8 +527,11 @@ static size_t maxArgWidth(const struct poptOption * opt,
if (opt != NULL)
while (opt->longName || opt->shortName || opt->arg) {
if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
@ -32,7 +45,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.h
if (len > max) max = len;
} else if (!F_ISSET(opt, DOC_HIDDEN)) {
len = sizeof(" ")-1;
@@ -619,19 +622,22 @@ static void singleTableHelp(poptContext
@@ -619,19 +622,22 @@ static void singleTableHelp(poptContext con, FILE * fp,
if (table != NULL)
for (opt = table; opt->longName || opt->shortName || opt->arg; opt++) {
@ -58,7 +71,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.h
}
}
@@ -808,22 +814,25 @@ static size_t singleTableUsage(poptConte
@@ -808,22 +814,25 @@ static size_t singleTableUsage(poptContext con, FILE * fp, columns_t columns,
translation_domain = (const char *)opt->arg;
} else
if (poptArgType(opt) == POPT_ARG_INCLUDE_TABLE) {
@ -88,7 +101,7 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.h
translation_domain, done);
} else
if ((opt->longName || opt->shortName) && !F_ISSET(opt, DOC_HIDDEN)) {
@@ -864,9 +873,13 @@ static size_t showShortOptions(const str
@@ -864,9 +873,13 @@ static size_t showShortOptions(const struct poptOption * opt, FILE * fp,
if (!strchr(s, opt->shortName) && isprint((int)opt->shortName)
&& opt->shortName != ' ')
s[strlen(s)] = opt->shortName;
@ -105,3 +118,6 @@ This patch was proposed to upstream: http://rpm5.org/community/popt-devel/0287.h
}
/* On return to top level, print the short options, return print length. */
--
2.13.3

View File

@ -0,0 +1,79 @@
From 6fcb24d785a2c2d626bac6999aee6b3ab368be15 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 28 Jul 2017 16:11:40 -0400
Subject: [PATCH] Don't leak the last argument expanded by expandNextArg()
While using POPT_ARG_ARGV, I noticed this in valgrind's leak checker:
==1738== HEAP SUMMARY:
==1738== in use at exit: 8 bytes in 1 blocks
==1738== total heap usage: 94 allocs, 93 frees, 42,319 bytes allocated
==1738==
==1738== 8 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1738== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299)
==1738== by 0x4E3DF47: expandNextArg (popt.c:699)
==1738== by 0x4E3F681: poptGetNextOpt (popt.c:1501)
==1738== by 0x401F72: main (bingrep.c:433)
==1738==
==1738== LEAK SUMMARY:
==1738== definitely lost: 8 bytes in 1 blocks
==1738== indirectly lost: 0 bytes in 0 blocks
==1738== possibly lost: 0 bytes in 0 blocks
==1738== still reachable: 0 bytes in 0 blocks
==1738== suppressed: 0 bytes in 0 blocks
My command line argument is a 7-byte string, and on first glance, it
appears this is because both expandNextArg() and poptSaveString()
duplicate the string. The copy from poptSaveString() is the consuming
program's responsibility to free, but the intermediate pointer is popt's
responsibility.
Upon further examination, it appears popt normally does free this
string, but it only does it on the next entry to poptGetNextOpt(), and
on cleanOSE() in the case if we're not already at the bottom of
con->OptionStack.
This patch modifies poptResetContext() to ensure we'll always attempt to
free con->os->nextArg regardless of our position in the OptionStack, and
removes the duplicate free of con->os->argb in poptFreeContext(), as
it's called unconditionally by the poptResetContext() call on the
previous line.
This ensures that if poptGetNextOpt() isn't re-intered, poptFreeContext()
will free the memory that was allocated. Now valgrind tells me:
==31734== HEAP SUMMARY:
==31734== in use at exit: 0 bytes in 0 blocks
==31734== total heap usage: 94 allocs, 94 frees, 42,319 bytes allocated
==31734==
==31734== All heap blocks were freed -- no leaks are possible
Signed-off-by: Peter Jones <pjones@redhat.com>
---
popt.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/popt.c b/popt.c
index 1a53f40..72fbf5c 100644
--- a/popt.c
+++ b/popt.c
@@ -230,7 +230,7 @@ void poptResetContext(poptContext con)
con->os->argb = PBM_FREE(con->os->argb);
con->os->currAlias = NULL;
con->os->nextCharArg = NULL;
- con->os->nextArg = NULL;
+ con->os->nextArg = _free(con->os->nextArg);
con->os->next = 1; /* skip argv[0] */
con->numLeftovers = 0;
@@ -1617,7 +1617,6 @@ poptContext poptFreeContext(poptContext con)
{
if (con == NULL) return con;
poptResetContext(con);
- con->os->argb = _free(con->os->argb);
con->aliases = poptFreeItems(con->aliases, con->numAliases);
con->numAliases = 0;
--
2.13.3

View File

@ -1,15 +1,16 @@
Summary: C library for parsing command line parameters
Name: popt
Version: 1.16
Release: 9%{?dist}
Release: 10%{?dist}
License: MIT
Group: System Environment/Libraries
URL: http://www.rpm5.org/
Source: http://www.rpm5.org/files/%{name}/%{name}-%{version}.tar.gz
Patch0: popt-1.16-pkgconfig.patch
Patch1: popt-1.16-execfail.patch
Patch2: popt-1.16-man-page.patch
Patch3: popt-1.16-help.patch
Patch0001: 0001-Update-pkgconfig-directory.patch
Patch0002: 0002-kludge-poptBadOption-to-return-value-on-exec-alias-f.patch
Patch0003: 0003-Fix-some-spelling-mistakes-in-the-man-page.patch
Patch0004: 0004-Make-help-and-usage-translatable.patch
Patch0005: 0005-Don-t-leak-the-last-argument-expanded-by-expandNextA.patch
BuildRequires: gettext
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -43,11 +44,7 @@ The popt-static package includes static libraries of the popt library.
Install it if you need to link statically with libpopt.
%prep
%setup -q
%patch0 -p1 -b .pkgconfig
%patch1 -p1 -b .execfail
%patch2 -p1 -b .man-page
%patch3 -p1 -b .help
%autosetup -S git
%build
%if 0%{?fedora} < 17 && 0%{?rhel} < 7
@ -113,6 +110,10 @@ make check
%{_libdir}/libpopt.a
%changelog
* Fri Jul 28 2017 Peter Jones <pjones@redhat.com> - 1.16-10
- Make it use %%autosetup -S git
- Fix a memory leak
* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1.16-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild