[pacman-dev] BUG and PATCH: 'handle' not null after alpm_release()

Xavier Chantry shiningxc at gmail.com
Tue Jan 19 07:34:20 EST 2010


On Tue, Jan 19, 2010 at 12:37 PM, Markus Meissner <markus at evigo.net> wrote:
> Hi pacman dev list,
>
> I am the guy behind pyalpmm and I found a not so small bug in libalpm.
>
> As I wrote some unit-tests for pyalpmm I needed to open and close a
> libalpm-"session" multiple times without restarting the calling
> application. Something like that:
>
> 1. alpm_initialize();
> 2. /** do some operation here **/
> 3. alpm_release();
> 4. alpm_initialize();
> 5. alpm_release();
>
> But I couldn't do this, because the alpm_initialize() call in line 4
> always threw an error (errno: PM_ERR_HANDLE_NOT_NULL), which translates
> to: "library already initialized". This is obviously not true, because
> the alpm_release() function was successfully called.
>
>
> I checked the code and found out that this line threw the error:
>
> ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
>
> What means that the handle is not correctly reseted to NULL, but the
> _alpm_free_handle() function, which is called by alpm_release() has a
> FREE(handle) inside. So here is my explanation why this happens:
>
> The handle pointer is passed to _alpm_free_handle() as a value, so the
> pointer value itself is copied. This works perfect for freeing the
> contents of the handle struct, BUT setting this handle pointer to NULL
> just sets the locally copied pointer to NULL, what means the original
> handle variable remains un-touched. So every alpm_initialize() call
> after the first one will throw this error, no matter if you called
> alpm_release() or not.
>
> So to get finally end, I fixed it and the patch is (against latest git)
> attached to this email. Hopefully my explanation is enough to sketch the
> problem. Solving it, is really easy, just change the _alpm_free_handle()
> function to take a pointer of a pointer of pmhandle_t as an argument,
> change the references to handle inside the function and slightly change
> the _alpm_free_handle() call in alpm_release(). That's how it is done
> with the attached patch...
>

What about just doing handle = NULL after the _alpm_free_handle() call ?

> Finally I also have a question: I saw many changes in the recent git
> compared to the latest release. Is there an estimated release date?
>

Not afaik. There was a plan to include some features (mainly GPG) for
the next release that no one is working on.
I wonder if we should not release anyway, because there are already
some nice changes.


More information about the pacman-dev mailing list