On Tue, Oct 8, 2019 at 12:10 AM Maciej Żenczykowski <zenczykow...@gmail.com> wrote: > > Here's my reasoning: > > old = ct->ext; > > //... stuff that doesn't change old. > > alloc = max(newlen, NF_CT_EXT_PREALLOC); <-- will be >= 128, > so not zero > kmemleak_not_leak(old); > new = __krealloc(old, alloc, gfp); > if (!new) > return NULL; <--- if we return here, ct->ext still > holds old, so no leak. > > if (!old) { > memset(new->offset, 0, sizeof(new->offset)); > ct->ext = new; <--- old is NULL so can't leak > } else if (new != old) { > kfree_rcu(old, rcu); <-- we free old, so doesn't leak > rcu_assign_pointer(ct->ext, new); > } <--- else new == old && it's still in ct->ext, so it doesn't leak >
So you conclude as it is not leak too? Then what are you trying to fix? I am becoming more confused after this. :-/ > Basically AFAICT our use of __krealloc() is exactly like krealloc() > except instead of kfree() we do kfree_rcu(). > > And thus I don't understand the need for kmemleak_not_leak(old). kfree_rcu() is a callback deferred after a grace period, so if we allocate the memory again before that callback, it is reported to kmemleak as a memory leak unless we mark it as not, right? Or kfree_rcu() works nicely with kmemleak which I am not aware of? Thanks.