Red Hat Bugzilla – Bug 153163
lib/poptQV.c::rpmQVSourceArgCallback() is called twice for each query arg
Last modified: 2007-11-30 17:07:06 EST
Description of problem:
I have to say this is really, bizarre, but I was trying to add a --target
rpm -q --specfile blah.spec
rpm -q --specfile blah.spec --target ia32e
And when I ran the query I would always end up with the query ran twice.
I eventually added debug code in rpmQVSourceArgCallback(), and noted that for
every --target I added the callback would be called twice. I then added
debug output to the part of the case statement that handled --specfile, and
found that it indeed was called twice for that too. So it seems like
the query args callback gets called twice for each query arg.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Patch lib/poptQV.c::rpmQVSourceArgCallback() to do debug print for each
part of the case statement.
2. Run a query with this rpm you build.
It will print a debug message twice for each command line arg.
It should only print it once.
The problem seems to be masked in that most of the query args only take one
arg, and thus memory is just reallocated each time, and the old string is lost.
I bet if you ran it through valgrind though you would at least note a memory
leak on --specfile when on the second call it doesn't free() the initial memory
Obviously, everything "works" right now, so I put this as a low priority bug.
I looked at this further, and the reason this occurs is that there is a "popt"
table defined called rpmQVSourcePoptTable. This table is included in both
rpmQueryPoptTable, and rpmVerifyPoptTable. The end result is that
any options defined in this table get acted on twice.
In my case I simply needed to add my option to rpmQueryPoptTable, as it made
since for it to be used by -V. I still kind of think this is a bug, albeit a
very minor one. I am not sure how you would work around it though, as it would
have to occur in popt itself. Maybe, popt should keep a record of what
callbacks it has made and not make them twice. I see what is being done in the
code (basically avoiding declaring this information twice), so it seems
reasonable popt should support this without unexpected/likely unwanted side
Tables need to be called multiple times because of multiple usages of various
options like -i and --target. There's no avoiding the aliasing except by making
the options unique per table.