Bug 153163 - lib/poptQV.c::rpmQVSourceArgCallback() is called twice for each query arg
lib/poptQV.c::rpmQVSourceArgCallback() is called twice for each query arg
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: rpm (Show other bugs)
3.0
All Linux
medium Severity low
: ---
: ---
Assigned To: Paul Nasrat
Mike McLean
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-01 16:53 EST by James Olin Oden
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-02-12 13:44:58 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description James Olin Oden 2005-04-01 16:53:10 EST
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 09:19:16 EDT
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 13:44:58 EST
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.

Note You need to log in before you can comment on or make changes to this bug.