Skip to content

Commit

Permalink
block: Add bdrv_reopen_queue_free()
Browse files Browse the repository at this point in the history
Move the code to free a BlockReopenQueue to a separate function.
It will be used in a subsequent patch.

[ kwolf: Also free explicit_options and options, and explicitly
  qobject_ref() the value when it continues to be used. This makes
  future memory leaks less likely. ]

Signed-off-by: Alberto Garcia <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
bertogg authored and kevmw committed Jul 9, 2021
1 parent bcfd86d commit ab5b522
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,19 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
NULL, 0, keep_old_opts);
}

void bdrv_reopen_queue_free(BlockReopenQueue *bs_queue)
{
if (bs_queue) {
BlockReopenQueueEntry *bs_entry, *next;
QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
qobject_unref(bs_entry->state.explicit_options);
qobject_unref(bs_entry->state.options);
g_free(bs_entry);
}
g_free(bs_queue);
}
}

/*
* Reopen multiple BlockDriverStates atomically & transactionally.
*
Expand Down Expand Up @@ -4197,15 +4210,10 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
if (bs_entry->prepared) {
bdrv_reopen_abort(&bs_entry->state);
}
qobject_unref(bs_entry->state.explicit_options);
qobject_unref(bs_entry->state.options);
}

cleanup:
QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
g_free(bs_entry);
}
g_free(bs_queue);
bdrv_reopen_queue_free(bs_queue);

return ret;
}
Expand Down Expand Up @@ -4573,6 +4581,8 @@ static void bdrv_reopen_commit(BDRVReopenState *reopen_state)
/* set BDS specific flags now */
qobject_unref(bs->explicit_options);
qobject_unref(bs->options);
qobject_ref(reopen_state->explicit_options);
qobject_ref(reopen_state->options);

bs->explicit_options = reopen_state->explicit_options;
bs->options = reopen_state->options;
Expand Down
1 change: 1 addition & 0 deletions include/block/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ BlockDriverState *bdrv_new_open_driver(BlockDriver *drv, const char *node_name,
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
BlockDriverState *bs, QDict *options,
bool keep_old_opts);
void bdrv_reopen_queue_free(BlockReopenQueue *bs_queue);
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
int bdrv_reopen_set_read_only(BlockDriverState *bs, bool read_only,
Error **errp);
Expand Down

0 comments on commit ab5b522

Please sign in to comment.