[pacman-dev] [PATCH] _alpm_backup_dup: fix memory leak in error case

Allan McRae allan at archlinux.org
Mon Nov 17 14:51:39 UTC 2014


Signed-off-by: Allan McRae <allan at archlinux.org>
---
 lib/libalpm/backup.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index c2989b6..aeb4131 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -87,10 +87,15 @@ alpm_backup_t *_alpm_backup_dup(const alpm_backup_t *backup)
 	alpm_backup_t *newbackup;
 	CALLOC(newbackup, 1, sizeof(alpm_backup_t), return NULL);
 
-	STRDUP(newbackup->name, backup->name, return NULL);
-	STRDUP(newbackup->hash, backup->hash, return NULL);
+	STRDUP(newbackup->name, backup->name, goto error);
+	STRDUP(newbackup->hash, backup->hash, goto error);
 
 	return newbackup;
+
+error:
+	free(newbackup->name);
+	free(newbackup);
+	return NULL;
 }
 
 /* vim: set noet: */
-- 
2.1.3


More information about the pacman-dev mailing list