summaryrefslogtreecommitdiff
path: root/src/collect/collect.c
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 /src/collect/collect.c
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>
Diffstat (limited to 'src/collect/collect.c')
-rw-r--r--src/collect/collect.c20
1 files changed, 7 insertions, 13 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)