summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2013-07-30 13:46:21 -0400
committerAnthony G. Basile <blueness@gentoo.org>2013-07-30 13:46:21 -0400
commit38382ffbd6bca77680042f967fa8fc5a560fae07 (patch)
tree47200f07dd854fb6694d745b5d72941a2e77f18e
parentf6571c3d6454c43956ca243d92d0229ed5a07d8d (diff)
Bring collect.c and udevadm-hwdb.c in line with upstream
This brings these two files in line with upstream's commit: ef89eef77ee098a6828169a6d0d74128e236bcbd udev: fix two trivial memleaks in error path Based-on-a-patch-by: Ian Stakenvicius <axs@gentoo.org> Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/collect/collect.c20
-rw-r--r--src/udev/udevadm-hwdb.c2
2 files changed, 8 insertions, 14 deletions
diff --git a/src/collect/collect.c b/src/collect/collect.c
index e938d41728..1346f27f91 100644
--- a/src/collect/collect.c
+++ b/src/collect/collect.c
@@ -104,8 +104,7 @@ static int prepare(char *dir, char *filename)
fprintf(stderr, "Lock taken, wait for %d seconds\n", UDEV_ALARM_TIMEOUT);
if (errno == EAGAIN || errno == EACCES) {
alarm(UDEV_ALARM_TIMEOUT);
- if (lockf(fd, F_LOCK, 0) == -1)
- fprintf(stderr, "Failed to acquire lock on %s\n", buf);
+ lockf(fd, F_LOCK, 0);
if (debug)
fprintf(stderr, "Acquired lock on %s\n", buf);
} else {
@@ -141,10 +140,8 @@ static int checkout(int fd)
restart:
len = bufsize >> 1;
buf = malloc(bufsize + 1);
- if (!buf) {
- fprintf(stderr, "Out of memory.\n");
+ if (!buf)
return log_oom();
- }
memset(buf, ' ', bufsize);
buf[bufsize] = '\0';
@@ -445,20 +442,19 @@ int main(int argc, char **argv)
if (debug)
fprintf(stderr, "ID %s: not in database\n", argv[i]);
- him = malloc(sizeof (struct _mate));
+ him = new(struct _mate, 1);
if (!him) {
ret = ENOMEM;
goto out;
}
- him->name = malloc(strlen(argv[i]) + 1);
+ him->name = strdup(argv[i]);
if (!him->name) {
- free(him); /* clang reported memleak ; him is thrown away here */
+ free(him);
ret = ENOMEM;
goto out;
}
- strcpy(him->name, argv[i]);
him->state = STATE_NONE;
udev_list_node_append(&him->node, &bunch);
} else {
@@ -480,12 +476,10 @@ int main(int argc, char **argv)
kickout();
lseek(fd, 0, SEEK_SET);
- if (ftruncate(fd, 0) == -1)
- fprintf(stderr, "Failed to truncate '%s'\n", checkpoint);
+ ftruncate(fd, 0);
ret = missing(fd);
- if (lockf(fd, F_ULOCK, 0) == -1)
- fprintf(stderr, "Failed to release lock from '%s'\n", checkpoint);
+ lockf(fd, F_ULOCK, 0);
close(fd);
out:
if (debug)
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index 8f5b1cb7a1..aa590d550f 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -304,7 +304,7 @@ static int64_t trie_store_nodes(struct trie_f *trie, struct trie_node *node) {
child_off = trie_store_nodes(trie, node->children[i].child);
if (child_off < 0) {
- free(children); /* clang reported memleak , children is thrown away if this fails */
+ free(children);
return child_off;
}
children[i].c = node->children[i].c;