From 6e7d597a50b4ef878b45c82c3e6f086dbd5ec1b1 Mon Sep 17 00:00:00 2001 From: Dave Wysochanski Date: Wed, 8 Jul 2009 22:18:32 +0000 Subject: [PATCH] Make exit paths more robust when some init function fails. Author: Dave Wysochanski --- lib/format_text/archiver.c | 4 ++++ lib/label/label.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c index d80c0bad5..a8520bb0a 100644 --- a/lib/format_text/archiver.c +++ b/lib/format_text/archiver.c @@ -65,6 +65,8 @@ int archive_init(struct cmd_context *cmd, const char *dir, void archive_exit(struct cmd_context *cmd) { + if (!cmd->archive_params) + return; if (cmd->archive_params->dir) dm_free(cmd->archive_params->dir); memset(cmd->archive_params, 0, sizeof(*cmd->archive_params)); @@ -175,6 +177,8 @@ int backup_init(struct cmd_context *cmd, const char *dir, void backup_exit(struct cmd_context *cmd) { + if (!cmd->backup_params) + return; if (cmd->backup_params->dir) dm_free(cmd->backup_params->dir); memset(cmd->backup_params, 0, sizeof(*cmd->backup_params)); diff --git a/lib/label/label.c b/lib/label/label.c index 8924735d3..25f520a0c 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -72,7 +72,7 @@ void label_exit(void) struct dm_list *c, *n; struct labeller_i *li; - for (c = _labellers.n; c != &_labellers; c = n) { + for (c = _labellers.n; c && c != &_labellers; c = n) { n = c->n; li = dm_list_item(c, struct labeller_i); li->l->ops->destroy(li->l);