[pacman-dev] [BUG] alpm_list_remove need an initalized pointer for void **data

Dan McGee dpmcgee at gmail.com
Thu Aug 7 09:41:17 EDT 2008

On Thu, Aug 7, 2008 at 7:42 AM, solsTiCe d'Hiver
<solstice.dhiver at gmail.com> wrote:
> hi.
> i am playing with alpm and db4 to make a little program for me. just for fun.
> and in this new release of libalpm (along pacman 3.2.0) i have found that
> alpm_list_remove behave differently than before. so the last parameter (void
> **data) need to be initialized to avoid a seg fault.
> it happens in alpm_db_unregister if you unregister a sync db
> if you run this, you will see it happen
> #include <stdio.h>
> #include <stdlib.h>
> #include <alpm.h>
> int main(void) {
>    pmdb_t *db;
>    pmpkg_t *pkg;
>    const char *s;
>    alpm_initialize();
>    alpm_option_set_root("/");
>    alpm_option_set_dbpath("/var/lib/pacman");
>    alpm_option_add_cachedir("/var/cache/pacman/pkg");
>    alpm_option_set_logfile("/dev/stdout");
>    db = alpm_db_register_sync("extra");
>    puts("alpm_db_unregister(db)");
>    alpm_db_unregister(db);
>    puts("alpm_release()");
>    alpm_release();
>    exit(EXIT_SUCCESS);
> }
> i wonder how it has not generated more bug in libalpm.

I think the problem is something different; note the problem occurs in db_cmp:

Program received signal SIGSEGV, Segmentation fault.
_alpm_db_cmp (d1=0x97b60f0, d2=0x97b60f0) at db.c:363
363             return(strcmp(db1->treename, db2->treename));
(gdb) bt
#0  _alpm_db_cmp (d1=0x97b60f0, d2=0x97b60f0) at db.c:363
#1  0xb8006a8c in alpm_list_remove (haystack=0x97b6140, needle=0x97b60f0,
    fn=0xb800d5b0 <_alpm_db_cmp>, data=0xbf841064) at alpm_list.c:314
#2  0xb800ead2 in alpm_db_unregister (db=0x97b60f0) at db.c:149
#3  0x08048770 in main () at test.c:17
(gdb) p d1
$1 = (const void *) 0x97b60f0
(gdb) p d2
$2 = (const void *) 0x97b60f0
(gdb) p d1->treename
Attempt to dereference a generic pointer.
(gdb) p ((pmdb_t)d1)->treename
$3 = 0x97b60f0 "\020a{\t0a{\t\220p{\t"
(gdb) p ((pmdb_t)d2)->treename
$4 = 0x0

I'm not completely sure what is going on here.

Here is the start of list_remove. If data is anything except null, we
set it to null anyway:
alpm_list_t SYMEXPORT *alpm_list_remove(alpm_list_t *haystack, const
void *needle, alpm_list_fn_cmp fn, void **data)
  alpm_list_t *i = haystack, *tmp = NULL;

  if(data) {
    *data = NULL;


More information about the pacman-dev mailing list