Commit fac3689e authored by Andrew Jeffery's avatar Andrew Jeffery

dbus: Unref replies to avoid leaks

Testing showed that failing to free DBus message replies was leaking
800-900kiB per boot. After adding the appropriate unrefs, mboxd memory
consumption stayed stable at 71920kiB across multiple reboots of the
host.

The root cause was identified using a DBus capture of the host's IPMI
traffic during boot, then reducing the output to mboxd-specific messages
and turning them into commands that could be run with ipmitool. Adding
all of these commands to a script and running `pmap` between ipmitool
invocations showed the growth in memory usage across the "boot" process,
but this did not correlate with any particular set of commands to mboxd.
The lack of correlation lead to the hypothesis that we might be able to
reproduce by sending a lot of dbus messages, such as:

```
root@witherspoon:/tmp# for i in `seq 1 10000`; do \
busctl call xyz.openbmc_project.Hiomapd \
	/xyz/openbmc_project/Hiomapd \
	xyz.openbmc_project.Hiomapd.Protocol.V2 \
	GetInfo y 2; \
done
```

Spamming the daemon in this way demonstrated the growth in memory seen
during a regular boot process, confirming that just sending DBus
messages was enough.

Add the necessary unrefs for the replies at the end of each method
handler to ensure the replies are appropriately freed.

Testing and confirmation of the fix were performed on a Witherspoon
system.

Change-Id: If5fe7576aaca1be617181526bf64511ccee1dd9f
Signed-off-by: Andrew Jeffery's avatarAndrew Jeffery <andrew@aj.id.au>
parent a804a73c
...@@ -43,7 +43,9 @@ static int control_dbus_directive(sd_bus_message *m, void *userdata, ...@@ -43,7 +43,9 @@ static int control_dbus_directive(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int control_dbus_ping(sd_bus_message *m, void *userdata, static int control_dbus_ping(sd_bus_message *m, void *userdata,
...@@ -190,7 +192,9 @@ static int control_dbus_set_backend(sd_bus_message *m, void *userdata, ...@@ -190,7 +192,9 @@ static int control_dbus_set_backend(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int control_dbus_get_u8(sd_bus *bus, const char *path, static int control_dbus_get_u8(sd_bus *bus, const char *path,
......
...@@ -278,6 +278,7 @@ out: ...@@ -278,6 +278,7 @@ out:
} }
rc = sd_bus_send(NULL, n, NULL); /* Send response */ rc = sd_bus_send(NULL, n, NULL); /* Send response */
sd_bus_message_unref(n);
if (rc < 0) if (rc < 0)
MSG_ERR("sd_bus_send failed: %d\n", rc); MSG_ERR("sd_bus_send failed: %d\n", rc);
......
...@@ -93,7 +93,9 @@ static int transport_dbus_reset(sd_bus_message *m, void *userdata, ...@@ -93,7 +93,9 @@ static int transport_dbus_reset(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_get_info(sd_bus_message *m, void *userdata, static int transport_dbus_get_info(sd_bus_message *m, void *userdata,
...@@ -146,7 +148,9 @@ static int transport_dbus_get_info(sd_bus_message *m, void *userdata, ...@@ -146,7 +148,9 @@ static int transport_dbus_get_info(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_get_flash_info(sd_bus_message *m, void *userdata, static int transport_dbus_get_flash_info(sd_bus_message *m, void *userdata,
...@@ -181,7 +185,9 @@ static int transport_dbus_get_flash_info(sd_bus_message *m, void *userdata, ...@@ -181,7 +185,9 @@ static int transport_dbus_get_flash_info(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_create_window(struct mbox_context *context, static int transport_dbus_create_window(struct mbox_context *context,
...@@ -225,7 +231,9 @@ static int transport_dbus_create_window(struct mbox_context *context, ...@@ -225,7 +231,9 @@ static int transport_dbus_create_window(struct mbox_context *context,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_create_read_window(sd_bus_message *m, void *userdata, static int transport_dbus_create_read_window(sd_bus_message *m, void *userdata,
...@@ -274,7 +282,9 @@ static int transport_dbus_close_window(sd_bus_message *m, void *userdata, ...@@ -274,7 +282,9 @@ static int transport_dbus_close_window(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
...@@ -308,7 +318,9 @@ static int transport_dbus_mark_dirty(sd_bus_message *m, void *userdata, ...@@ -308,7 +318,9 @@ static int transport_dbus_mark_dirty(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_write_flush(sd_bus_message *m, void *userdata, static int transport_dbus_write_flush(sd_bus_message *m, void *userdata,
...@@ -334,7 +346,9 @@ static int transport_dbus_write_flush(sd_bus_message *m, void *userdata, ...@@ -334,7 +346,9 @@ static int transport_dbus_write_flush(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_ack(sd_bus_message *m, void *userdata, static int transport_dbus_ack(sd_bus_message *m, void *userdata,
...@@ -367,7 +381,9 @@ static int transport_dbus_ack(sd_bus_message *m, void *userdata, ...@@ -367,7 +381,9 @@ static int transport_dbus_ack(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_erase(sd_bus_message *m, void *userdata, static int transport_dbus_erase(sd_bus_message *m, void *userdata,
...@@ -400,7 +416,9 @@ static int transport_dbus_erase(sd_bus_message *m, void *userdata, ...@@ -400,7 +416,9 @@ static int transport_dbus_erase(sd_bus_message *m, void *userdata,
return rc; return rc;
} }
return sd_bus_send(NULL, n, NULL); rc = sd_bus_send(NULL, n, NULL);
sd_bus_message_unref(n);
return rc;
} }
static int transport_dbus_get_property(sd_bus *bus, static int transport_dbus_get_property(sd_bus *bus,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment