Skip to content

Commit ec62164

Browse files
authored
Merge pull request #2972 from sebastiankuttnig/memleak
drivers/main.c, drivers/dummy-ups.c: fix memory issues
2 parents c034ef1 + a1210ef commit ec62164

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

drivers/dummy-ups.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -564,22 +564,26 @@ void upsdrv_initups(void)
564564

565565
void upsdrv_cleanup(void)
566566
{
567-
if ( (mode == MODE_META) || (mode == MODE_REPEATER) )
568-
{
569-
if (ups)
570-
{
571-
upscli_disconnect(ups);
572-
}
573-
574-
if (ctx)
575-
{
576-
pconf_finish(ctx);
577-
free(ctx);
578-
}
567+
if (ups) {
568+
upscli_disconnect(ups);
569+
free(ups);
570+
ups = NULL;
571+
}
579572

573+
if (client_upsname) {
580574
free(client_upsname);
575+
client_upsname = NULL;
576+
}
577+
578+
if (hostname) {
581579
free(hostname);
582-
free(ups);
580+
hostname = NULL;
581+
}
582+
583+
if (ctx) {
584+
pconf_finish(ctx);
585+
free(ctx);
586+
ctx = NULL;
583587
}
584588
}
585589

drivers/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1792,11 +1792,16 @@ static void splitxarg(char *inbuf)
17921792
}
17931793

17941794
/* see if main handles this first */
1795-
if (main_arg(buf, val))
1795+
if (main_arg(buf, val)) {
1796+
free(buf);
1797+
17961798
return;
1799+
}
17971800

17981801
/* otherwise store it for later */
17991802
storeval(buf, val);
1803+
1804+
free(buf);
18001805
}
18011806

18021807
/* dump the list from the vartable for external parsers */

0 commit comments

Comments
 (0)