Skip to content

Commit

Permalink
dm snapshot persistent: fix missing cleanup in persistent_ctr error path
Browse files Browse the repository at this point in the history
If an unsupported option is given then the early return from
persistent_ctr() leaked memory allocated for the 'pstore' and never
destroyed the 'metadata_wq'.

Fixes: b0d3cc0 ("dm snapshot: add new persistent store option to support overflow")
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Sudip Mukherjee authored and Mike Snitzer committed Oct 13, 2015
1 parent 25cb62b commit a2a678e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions drivers/md/dm-snap-persistent.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ static void persistent_drop_snapshot(struct dm_exception_store *store)
static int persistent_ctr(struct dm_exception_store *store, char *options)
{
struct pstore *ps;
int r;

/* allocate the pstore */
ps = kzalloc(sizeof(*ps), GFP_KERNEL);
Expand All @@ -868,9 +869,9 @@ static int persistent_ctr(struct dm_exception_store *store, char *options)

ps->metadata_wq = alloc_workqueue("ksnaphd", WQ_MEM_RECLAIM, 0);
if (!ps->metadata_wq) {
kfree(ps);
DMERR("couldn't start header metadata update thread");
return -ENOMEM;
r = -ENOMEM;
goto err_workqueue;
}

if (options) {
Expand All @@ -879,13 +880,21 @@ static int persistent_ctr(struct dm_exception_store *store, char *options)
store->userspace_supports_overflow = true;
else {
DMERR("Unsupported persistent store option: %s", options);
return -EINVAL;
r = -EINVAL;
goto err_options;
}
}

store->context = ps;

return 0;

err_options:
destroy_workqueue(ps->metadata_wq);
err_workqueue:
kfree(ps);

return r;
}

static unsigned persistent_status(struct dm_exception_store *store,
Expand Down

0 comments on commit a2a678e

Please sign in to comment.