On 25 July 2018 at 09:59, Stefan Hajnoczi <[email protected]> wrote: > Image file loaders may add a series of roms. If an error occurs partway > through loading there is no easy way to drop previously added roms. > > This patch adds a transaction mechanism that works like this: > > rom_transaction_begin(); > ...call rom_add_*()... > rom_transaction_end(ok); > > If ok is false then roms added in this transaction are dropped. > > Signed-off-by: Stefan Hajnoczi <[email protected]> > --- > +void rom_transaction_end(bool commit) > +{ > + Rom *rom; > + Rom *tmp; > + > + QTAILQ_FOREACH_SAFE(rom, &roms, next, tmp) { > + if (rom->committed) { > + continue; > + } > + if (commit) { > + rom->committed = true; > + } else { > + QTAILQ_REMOVE(&roms, rom, next); > + g_free(rom->data); > + g_free(rom->path); > + g_free(rom->name); > + g_free(rom->fw_dir); > + g_free(rom->fw_file); > + g_free(rom);
Is it worth having a rom_free() function so we can share the "free all the pointers" code between this and the error-exit codepath at the end of rom_add_file() ? Either way Reviewed-by: Peter Maydell <[email protected]> thanks -- PMM
