Merge pull request #8142 from yuwata/sd-bus-memleak
Fix potential memory leaks and several code style updates
This commit is contained in:
commit
8c2dbc8779
|
@ -709,7 +709,7 @@ static int mount_coldplug(Unit *u) {
|
|||
}
|
||||
|
||||
static void mount_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
char buf[FORMAT_TIMESPAN_MAX] = {};
|
||||
char buf[FORMAT_TIMESPAN_MAX];
|
||||
Mount *m = MOUNT(u);
|
||||
MountParameters *p;
|
||||
|
||||
|
|
|
@ -774,8 +774,8 @@ static int service_load(Unit *u) {
|
|||
}
|
||||
|
||||
static void service_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
char buf_restart[FORMAT_TIMESPAN_MAX] = {}, buf_start[FORMAT_TIMESPAN_MAX] = {}, buf_stop[FORMAT_TIMESPAN_MAX] = {};
|
||||
char buf_runtime[FORMAT_TIMESPAN_MAX] = {}, buf_watchdog[FORMAT_TIMESPAN_MAX] = {};
|
||||
char buf_restart[FORMAT_TIMESPAN_MAX], buf_start[FORMAT_TIMESPAN_MAX], buf_stop[FORMAT_TIMESPAN_MAX];
|
||||
char buf_runtime[FORMAT_TIMESPAN_MAX], buf_watchdog[FORMAT_TIMESPAN_MAX];
|
||||
ServiceExecCommand c;
|
||||
Service *s = SERVICE(u);
|
||||
const char *prefix2;
|
||||
|
|
|
@ -559,7 +559,7 @@ static int swap_coldplug(Unit *u) {
|
|||
}
|
||||
|
||||
static void swap_dump(Unit *u, FILE *f, const char *prefix) {
|
||||
char buf[FORMAT_TIMESPAN_MAX] = {};
|
||||
char buf[FORMAT_TIMESPAN_MAX];
|
||||
Swap *s = SWAP(u);
|
||||
SwapParameters *p;
|
||||
|
||||
|
|
|
@ -286,8 +286,7 @@ _public_ int sd_bus_set_address(sd_bus *bus, const char *address) {
|
|||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
free(bus->address);
|
||||
bus->address = a;
|
||||
free_and_replace(bus->address, a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -325,10 +324,9 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[])
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
free(bus->exec_path);
|
||||
strv_free(bus->exec_argv);
|
||||
free_and_replace(bus->exec_path, p);
|
||||
|
||||
bus->exec_path = p;
|
||||
strv_free(bus->exec_argv);
|
||||
bus->exec_argv = a;
|
||||
|
||||
return 0;
|
||||
|
@ -351,7 +349,7 @@ _public_ int sd_bus_set_monitor(sd_bus *bus, int b) {
|
|||
assert_return(bus->state == BUS_UNSET, -EPERM);
|
||||
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||
|
||||
bus->is_monitor = b;
|
||||
bus->is_monitor = !!b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -361,7 +359,7 @@ _public_ int sd_bus_negotiate_fds(sd_bus *bus, int b) {
|
|||
assert_return(bus->state == BUS_UNSET, -EPERM);
|
||||
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||
|
||||
bus->accept_fd = b;
|
||||
bus->accept_fd = !!b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -373,7 +371,7 @@ _public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) {
|
|||
|
||||
/* This is not actually supported by any of our transports these days, but we do honour it for synthetic
|
||||
* replies, and maybe one day classic D-Bus learns this too */
|
||||
bus->attach_timestamp = b;
|
||||
bus->attach_timestamp = !!b;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -457,7 +455,7 @@ _public_ int sd_bus_set_watch_bind(sd_bus *bus, int b) {
|
|||
assert_return(bus->state == BUS_UNSET, -EPERM);
|
||||
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||
|
||||
bus->watch_bind = b;
|
||||
bus->watch_bind = !!b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -475,7 +473,7 @@ _public_ int sd_bus_set_connected_signal(sd_bus *bus, int b) {
|
|||
assert_return(bus->state == BUS_UNSET, -EPERM);
|
||||
assert_return(!bus_pid_changed(bus), -ECHILD);
|
||||
|
||||
bus->connected_signal = b;
|
||||
bus->connected_signal = !!b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -556,6 +554,7 @@ void bus_set_state(sd_bus *bus, enum bus_state state) {
|
|||
|
||||
static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *error) {
|
||||
const char *s;
|
||||
char *t;
|
||||
sd_bus *bus;
|
||||
int r;
|
||||
|
||||
|
@ -575,10 +574,12 @@ static int hello_callback(sd_bus_message *reply, void *userdata, sd_bus_error *e
|
|||
if (!service_name_is_valid(s) || s[0] != ':')
|
||||
return -EBADMSG;
|
||||
|
||||
bus->unique_name = strdup(s);
|
||||
if (!bus->unique_name)
|
||||
t = strdup(s);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
free_and_replace(bus->unique_name, t);
|
||||
|
||||
if (bus->state == BUS_HELLO) {
|
||||
bus_set_state(bus, BUS_RUNNING);
|
||||
|
||||
|
@ -649,8 +650,8 @@ int bus_start_running(sd_bus *bus) {
|
|||
|
||||
static int parse_address_key(const char **p, const char *key, char **value) {
|
||||
size_t l, n = 0, allocated = 0;
|
||||
_cleanup_free_ char *r = NULL;
|
||||
const char *a;
|
||||
char *r = NULL;
|
||||
|
||||
assert(p);
|
||||
assert(*p);
|
||||
|
@ -678,16 +679,12 @@ static int parse_address_key(const char **p, const char *key, char **value) {
|
|||
int x, y;
|
||||
|
||||
x = unhexchar(a[1]);
|
||||
if (x < 0) {
|
||||
free(r);
|
||||
if (x < 0)
|
||||
return x;
|
||||
}
|
||||
|
||||
y = unhexchar(a[2]);
|
||||
if (y < 0) {
|
||||
free(r);
|
||||
if (y < 0)
|
||||
return y;
|
||||
}
|
||||
|
||||
c = (char) ((x << 4) | y);
|
||||
a += 3;
|
||||
|
@ -714,8 +711,7 @@ static int parse_address_key(const char **p, const char *key, char **value) {
|
|||
|
||||
*p = a;
|
||||
|
||||
free(*value);
|
||||
*value = r;
|
||||
free_and_replace(*value, r);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1377,7 +1373,7 @@ fail:
|
|||
|
||||
int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
||||
_cleanup_free_ char *e = NULL;
|
||||
char *m = NULL, *c = NULL;
|
||||
char *m = NULL, *c = NULL, *a;
|
||||
|
||||
assert(b);
|
||||
assert(host);
|
||||
|
@ -1408,10 +1404,12 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) {
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
b->address = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=systemd-stdio-bridge", c);
|
||||
if (!b->address)
|
||||
a = strjoin("unixexec:path=ssh,argv1=-xT,argv2=--,argv3=", e, ",argv4=systemd-stdio-bridge", c);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
free_and_replace(b->address, a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1449,6 +1447,7 @@ fail:
|
|||
|
||||
int bus_set_address_system_machine(sd_bus *b, const char *machine) {
|
||||
_cleanup_free_ char *e = NULL;
|
||||
char *a;
|
||||
|
||||
assert(b);
|
||||
assert(machine);
|
||||
|
@ -1457,10 +1456,12 @@ int bus_set_address_system_machine(sd_bus *b, const char *machine) {
|
|||
if (!e)
|
||||
return -ENOMEM;
|
||||
|
||||
b->address = strjoin("x-machine-unix:machine=", e);
|
||||
if (!b->address)
|
||||
a = strjoin("x-machine-unix:machine=", e);
|
||||
if (!a)
|
||||
return -ENOMEM;
|
||||
|
||||
free_and_replace(b->address, a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
|
@ -18,9 +20,6 @@
|
|||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#ifndef _LIBUDEV_PRIVATE_H_
|
||||
#define _LIBUDEV_PRIVATE_H_
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
@ -146,5 +145,3 @@ uint64_t util_string_bloom64(const char *str);
|
|||
|
||||
/* libudev-util-private.c */
|
||||
int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue