[Nut-upsdev] Memory leak in upsmon
Arjen de Korte
nut+devel at de-korte.org
Sat Jan 26 16:14:38 UTC 2008
> I was running upsmon some time without UPS connected and noticed
> significant memory leak.
> After some debugging I found the leak source. It is in file
> Function upscli_connect() allocates memory for ups->pc_ctx and in case
> of any error, just returns -1 without freeing it.
I see, that's not nice.
> My NUT version is 2.2.0, but I quickly looked through 2.2.1 sources
> and it seems this bug was not fixed.
You're the first to report this, so indeed, it is in 2.2.1 too.
> So I include here simple patch. It uses goto to skip to free()
> allocated memory before returning in case of error. Sure one could
> rewrite it in more elegant way but nevertheless it helped me.
While I agree that this needs fixing, I don't like this patch. It would be
better to call upscli_disconnect() before returning with an error.
However, I'm not sure where to fix this. We could do this by default in
the upscli_connect() when something goes wrong, or it could be done by the
caller after upscli_connect() returns with an error. I'm not sure which
one would be cleaner.
Best regards, Arjen
Eindhoven - The Netherlands
Key fingerprint - 66 4E 03 2C 9D B5 CB 9B 7A FE 7E C1 EE 88 BC 57
More information about the Nut-upsdev