[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Is there a bug in headerFree? (rpm-4.0.3)



On Wed, Jul 04, 2001 at 03:24:54PM +0200, David Odin wrote:
> 
>   Hi,
> 
> I'm trying to print all the installed packages.
> The following program used to work with rpm-4.0.
> Now, it segfault on headerFree().
> It works well if I comment out the call to headerFree(), but I guess it then
> leaks some memory.
> 

No, deleting the headerFree() is the right thing to do, and it won't leak
memory.

You don't have to do headerFree() within the scope of rpmdbNextIterator(),
as the reference count is owned by the iterator.

> shouldn't we free headers in rpm-4.0.3 anymore?
> 

Alternatively, if you wish to use the Header outside of the while loop,
you should do
	h = headerLink(h)
inside the loop to bump the reference count on the Header. You'll need to do
a matching headerFree() later, or that will leak memory.

73 de Jeff

> -------------------------------------------------------------------
> #include <sys/stat.h>
> #include <fcntl.h>
> 
> 
> #include <rpm/rpmlib.h>
> #include <rpm/rpmio.h>
> #include <rpm/misc.h>
> 
> 
> int main(void)
> {
>   rpmdb db;
>   Header h;
>   char *buf;
>   int *size;
>   int type, count;
>   rpmdbMatchIterator iterator;
> 
>   rpmReadConfigFiles(NULL, NULL);
>   if (rpmdbOpen("", &db, O_RDONLY, 0644))
>   {
>     printf("Error!\n");exit(-1);
>   }
>   iterator = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
>   while ((h = rpmdbNextIterator(iterator)) != NULL)
>   {
>     if (!h)
>     {
>       printf("Error!\n");
>     }
>     headerGetEntry(h, RPMTAG_NAME, &type, (void **) &buf, &count);
>     printf("%s", buf);
>     headerGetEntry(h, RPMTAG_SIZE, &type, (void **) &size, &count);
>     headerGetEntry(h, RPMTAG_VERSION, &type, (void **) &buf, &count);
>     printf("-%s", buf);
>     headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) &buf, &count);
>     printf("-%s", buf);
>     headerGetEntry(h, RPMTAG_ARCH, &type, (void **) &buf, &count);
>     printf(".%s", buf);
> 
>     printf("\n");
>     headerFree(h);
>   }
>   rpmdbFreeIterator(iterator);
>   rpmdbClose(db);
> 
>   return 0;
> }
> --------------------------------------------------------------------
> 
>            Thanks,
> 
>                   DindinX
> 
> -- 
>   odin@mandrakesoft.com
> 
> 
> 
> _______________________________________________
> Rpm-list mailing list
> Rpm-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/rpm-list

-- 
Jeff Johnson	ARS N3NPQ
jbj@jbj.org	(jbj@redhat.com)
Chapel Hill, NC





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] []