Bug 153163

Summary: lib/poptQV.c::rpmQVSourceArgCallback() is called twice for each query arg
Product: Red Hat Enterprise Linux 3 Reporter: James Olin Oden <james.oden>
Component: rpmAssignee: Paul Nasrat <nobody+pnasrat>
Status: CLOSED WONTFIX QA Contact: Mike McLean <mikem>
Severity: low Docs Contact:
Priority: medium    
Version: 3.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2006-02-12 18:44:58 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description James Olin Oden 2005-04-01 21:53:10 UTC
Description of problem:
I have to say this is really, bizarre, but I was trying to add a --target 
option to:

   rpm -q --specfile blah.spec

as in:

   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):
4.2.3

How reproducible:
Very

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.
  
Actual results:

It will print a debug message twice for each command line arg.


Expected results:

It should only print it once.

Additional info:
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 
it allocated.

Obviously, everything "works" right now, so I put this as a low priority bug.

Comment 1 James Olin Oden 2005-04-04 13:19:16 UTC
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 
effect.

Comment 2 Jeff Johnson 2006-02-12 18:44:58 UTC
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.