shadow-maint / shadow

Upstream shadow tree
Other
287 stars 227 forks source link

src/groupmod.c: Memory leak? #1012

Closed alejandro-colomar closed 1 month ago

alejandro-colomar commented 1 month ago

https://github.com/shadow-maint/shadow/blob/4e2453fa9f0c1e0c18d1f118140af69d5fb82b8e/src/groupmod.c#L257-L261

Hi @hallyn ,

While checking code around, I stumbled upon this code, which you wrote, and I don't understand.

That program uses a lot of global state, and function pointers, so I may be missing something happening elsewhere.

However, this looks like duplicating memory, and leaking the old one, so we could just avoid that at all, no? Maybe you remember why you did it, and can explain why that's necessary, if it is.

Is the old list still referenced elsewhere after this line?

If not, we can simplify a little bit. :)

alejandro-colomar commented 1 month ago

I've found the other reference. grp = *ogrp makes a shallow copy of pointers, so I guess this makes the copy deep. *ogrp keeps the references to the old list.