[systemd-commits] 2 commits - src/libsystemd-bus src/shared src/sleep src/udev
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Sun Dec 15 14:52:10 PST 2013
src/libsystemd-bus/bus-objects.c | 10 +++++-----
src/shared/time-util.c | 2 +-
src/sleep/sleep.c | 15 +++++++--------
src/udev/net/link-config.c | 2 +-
src/udev/udev-builtin-net_id.c | 21 +++++++--------------
5 files changed, 21 insertions(+), 29 deletions(-)
New commits:
commit b5dd8148730db080b48b874c214f8f74ae787d6b
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun Dec 15 16:26:27 2013 -0500
Fix a few signed/unsigned format string issues
Since numbers involved are all small, behaviour was correct already.
https://bugzilla.redhat.com/show_bug.cgi?id=1043304
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 55428c4..678fd58 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -383,7 +383,7 @@ void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
assert(value);
assert(t);
- if (sscanf(value, "%lli %llu", &a, &b) != 2)
+ if (sscanf(value, "%llu %llu", &a, &b) != 2)
log_debug("Failed to parse finish timestamp value %s", value);
else {
t->realtime = a;
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index b859a6b..b91ca9d 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -166,23 +166,17 @@ out:
static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
struct udev *udev = udev_device_get_udev(names->pcidev);
- unsigned int domain;
- unsigned int bus;
- unsigned int slot;
- unsigned int func;
- unsigned int dev_id = 0;
+ unsigned domain, bus, slot, func, dev_id = 0;
size_t l;
char *s;
const char *attr;
struct udev_device *pci = NULL;
- char slots[256];
- DIR *dir;
+ char slots[256], str[256];
+ _cleanup_closedir_ DIR *dir = NULL;
struct dirent *dent;
- char str[256];
- int hotplug_slot = 0;
- int err = 0;
+ int hotplug_slot = 0, err = 0;
- if (sscanf(udev_device_get_sysname(names->pcidev), "%x:%x:%x.%d", &domain, &bus, &slot, &func) != 4)
+ if (sscanf(udev_device_get_sysname(names->pcidev), "%x:%x:%x.%u", &domain, &bus, &slot, &func) != 4)
return -ENOENT;
/* kernel provided multi-device index */
@@ -239,7 +233,6 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
if (hotplug_slot > 0)
break;
}
- closedir(dir);
if (hotplug_slot > 0) {
s = names->pci_slot;
@@ -341,11 +334,11 @@ static int names_bcma(struct udev_device *dev, struct netnames *names) {
return -ENOENT;
/* bus num:core num */
- if (sscanf(udev_device_get_sysname(bcmadev), "bcma%*d:%d", &core) != 1)
+ if (sscanf(udev_device_get_sysname(bcmadev), "bcma%*u:%u", &core) != 1)
return -EINVAL;
/* suppress the common core == 0 */
if (core > 0)
- snprintf(names->bcma_core, sizeof(names->bcma_core), "b%d", core);
+ snprintf(names->bcma_core, sizeof(names->bcma_core), "b%u", core);
names->type = NET_BCMA;
return 0;
commit 2fd069b18e525860514a70d3ea08410ca122d3e2
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun Dec 15 16:25:04 2013 -0500
Fix a few resource leaks in error paths
https://bugzilla.redhat.com/show_bug.cgi?id=1043304
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index 8c81ea6..5aa83a4 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -1338,7 +1338,8 @@ int bus_process_object(sd_bus *bus, sd_bus_message *m) {
static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
struct node *n, *parent;
const char *e;
- char *s, *p;
+ _cleanup_free_ char *s = NULL;
+ char *p;
int r;
assert(bus);
@@ -1366,10 +1367,8 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
p = strndupa(path, MAX(1, path - e));
parent = bus_node_allocate(bus, p);
- if (!parent) {
- free(s);
+ if (!parent)
return NULL;
- }
}
n = new0(struct node, 1);
@@ -1378,10 +1377,11 @@ static struct node *bus_node_allocate(sd_bus *bus, const char *path) {
n->parent = parent;
n->path = s;
+ s = NULL; /* do not free */
r = hashmap_put(bus->nodes, s, n);
if (r < 0) {
- free(s);
+ free(n->path);
free(n);
return NULL;
}
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index b6a6f60..bf67354 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -57,15 +57,14 @@ static int write_mode(char **modes) {
return r;
}
-static int write_state(FILE *f0, char **states) {
- FILE _cleanup_fclose_ *f = f0;
+static int write_state(FILE **f, char **states) {
char **state;
int r = 0;
STRV_FOREACH(state, states) {
int k;
- k = write_string_to_file(f, *state);
+ k = write_string_to_file(*f, *state);
if (k == 0)
return 0;
log_debug("Failed to write '%s' to /sys/power/state: %s",
@@ -73,9 +72,9 @@ static int write_state(FILE *f0, char **states) {
if (r == 0)
r = k;
- fclose(f);
- f = fopen("/sys/power/state", "we");
- if (!f) {
+ fclose(*f);
+ *f = fopen("/sys/power/state", "we");
+ if (!*f) {
log_error("Failed to open /sys/power/state: %m");
return -errno;
}
@@ -87,7 +86,7 @@ static int write_state(FILE *f0, char **states) {
static int execute(char **modes, char **states) {
char* arguments[4];
int r;
- FILE *f;
+ _cleanup_fclose_ FILE *f = NULL;
const char* note = strappenda("SLEEP=", arg_verb);
/* This file is opened first, so that if we hit an error,
@@ -115,7 +114,7 @@ static int execute(char **modes, char **states) {
note,
NULL);
- r = write_state(f, states);
+ r = write_state(&f, states);
if (r < 0)
return r;
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
index f25afa6..1a9d780 100644
--- a/src/udev/net/link-config.c
+++ b/src/udev/net/link-config.c
@@ -149,7 +149,7 @@ void link_config_ctx_free(link_config_ctx *ctx) {
static int load_link(link_config_ctx *ctx, const char *filename) {
link_config *link;
- FILE *file;
+ _cleanup_fclose_ FILE *file;
int r;
file = fopen(filename, "re");
More information about the systemd-commits
mailing list