Skip to content

If I reuse the same rpmtd for multiple headerGet() or rpmtdGetString() calls, would this cause a memory leak? #2492

Answered by pmatilai
shanebishop asked this question in Q&A
Discussion options

You must be logged in to vote

It's okay to reuse the same struct rpmtd_s for multiple calls, BUT each headerGet() needs to be paired with a rpmtdFreeData(), otherwise it will leak memory. The worse problem in the above is that string pointers you get this way turn to garbage on rpmdbNextIterator() - it will not matter for the above snippet but will likely come bite you once it grows into a larger program.

HEADERGET_DEFAULT is a braindamaged mode which returns pointers into header memory for some data and allocated for others, unless you're very sure of what you're doing, HEADERGET_ALLOC is the right mode to use with headerGet().

If you only need non-array data from the header, you might as well save yourself some pain…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pmatilai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants