[systemd-devel] [PATCH 2/2] sysv-generator: remove NULL pointer dereference

Lennart Poettering lennart at poettering.net
Mon Apr 27 06:50:35 PDT 2015


On Sun, 26.04.15 21:04, Thomas H.P. Andersen (phomes at gmail.com) wrote:

> On Sun, Apr 26, 2015 at 8:31 PM, Thomas H.P. Andersen <phomes at gmail.com> wrote:
> > On Sun, Apr 26, 2015 at 8:23 PM, Shawn Landden <shawn at churchofgit.com> wrote:
> >> Actually you missed that free_sysvstub_hashmap does not tolerate NULL pointers.
> > Indeed. I will commit that.
> 
> Wait. free_sysvstub_hashmapp does tolerate NULL pointers.
> 
> hashmap_steal_first will return NULL if the hashmap is NULL. And
> hashmap_free is fine with NULL too. Your patch makes it more obvious
> that free_sysvstub_hashmapp does tolerate NULL but destructors should
> tolerate NULL as per the coding style. So I guess it should just be
> assumed? I will leave it up to the others to decide what the best
> style is here.

Thomas, your are right.

The intention with hashmaps is that a NULL hashmap is considered
equivalent to an empty hashmap thus saving us tons of explicit
allocations while keeping the code reasable.

So yes, hashmap_steal_first() handles an empty hashmap correctly and
makes it a NOP retuning NULL, and so does hashmal_free().

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list