Skip to content

Commit

Permalink
Clean up format data after a failed probe
Browse files Browse the repository at this point in the history
Make sure that format-specific data is cleaned up after a failed probe.

Since private data may not be even allocated at that point, the cleanup
handlers must check that the pointer is not NULL before dereferencing it.
Add this check to devmem and lkcd cleanup handlers.

Signed-off-by: Petr Tesarik <[email protected]>
  • Loading branch information
ptesarik committed Sep 30, 2024
1 parent 24e53ed commit f191d5a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/kdumpfile/devmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ devmem_cleanup(struct kdump_shared *shared)
{
struct devmem_priv *dmp = shared->fmtdata;

if (!dmp)
return;

if (dmp->ce) {
free(dmp->ce[0].data);
free(dmp->ce);
Expand Down
3 changes: 3 additions & 0 deletions src/kdumpfile/lkcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,9 @@ lkcd_cleanup(struct kdump_shared *shared)
{
struct lkcd_priv *lkcdp = shared->fmtdata;

if (!lkcdp)
return;

free_level1(lkcdp->pfn_level1, lkcdp->l1_size);
mutex_destroy(&lkcdp->pfn_block_mutex);
if (lkcdp->cbuf_slot >= 0)
Expand Down
2 changes: 2 additions & 0 deletions src/kdumpfile/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ open_dump(kdump_ctx_t *ctx)
ret = ctx->shared->ops->probe(ctx);
if (ret == KDUMP_OK)
return finish_open_dump(ctx);
if (ctx->shared->ops->cleanup)
ctx->shared->ops->cleanup(ctx->shared);
if (ret != KDUMP_NOPROBE)
return ret;

Expand Down

0 comments on commit f191d5a

Please sign in to comment.