diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-12 13:53:19 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-12 13:53:19 +0200 |
commit | 275da329517b7d72abf25ce6a9ada48b142c64da (patch) | |
tree | 3896f70f687b493ea804a41d5346bcba6251ede9 | |
parent | Reduce coordinate details (diff) | |
download | libcontacts-275da329517b7d72abf25ce6a9ada48b142c64da.tar.gz libcontacts-275da329517b7d72abf25ce6a9ada48b142c64da.tar.bz2 libcontacts-275da329517b7d72abf25ce6a9ada48b142c64da.tar.xz |
Fix memory leak in libcontacts_save_contact
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libcontacts_save_contact.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libcontacts_save_contact.c b/libcontacts_save_contact.c index 89f8ebc..b373a46 100644 --- a/libcontacts_save_contact.c +++ b/libcontacts_save_contact.c @@ -31,7 +31,7 @@ makedirs(char *path) int libcontacts_save_contact(struct libcontacts_contact *contact, const struct passwd *user) { - char *data = NULL, *path = NULL, *tmppath; + char *data = NULL, *path = NULL, *tmppath = NULL; int oflags = O_WRONLY | O_CREAT | O_TRUNC; int fd = -1, saved_errno = errno, dirs_created = 0; ssize_t r; @@ -74,7 +74,7 @@ libcontacts_save_contact(struct libcontacts_contact *contact, const struct passw if (!path) goto fail; - tmppath = alloca(strlen(path) + sizeof("~")); + tmppath = malloc(strlen(path) + sizeof("~")); stpcpy(stpcpy(tmppath, path), "~"); if (oflags & O_EXCL) { @@ -93,6 +93,8 @@ libcontacts_save_contact(struct libcontacts_contact *contact, const struct passw basenam = contact->id; contact->id = NULL; } + free(path); + free(tmppath); goto generate_id; } close(fd); @@ -132,6 +134,7 @@ open_again: free(data); free(path); + free(tmppath); free(basenam); errno = saved_errno; return 0; @@ -142,6 +145,7 @@ fail: close(fd); free(data); free(path); + free(tmppath); free(basenam); errno = saved_errno; return -1; |