Skip to content

fix lifetime of MetadataINIWriter

Harald Sitter requested to merge work/ini-writer-init into master

this was previously might incorrect and could lead to crashes: we had a Writer* that would be null and conditionally assigned with the &ini, but ini was in a smaller scope effectively meaning that the pointer allowed for accessing an object past its lifetime.

Instead reshuffle the code a bunch to have the ini in the correct scope and use it from there without intermediate pointer or other trickery.

  • Metadata no longer accepts the backing writer as ctor argument. while that is nicer from an API POV it's also a bit cruddy to deal with considering ini is conditional on the build platform being linux AND functionally conditional on a path. instead the backing writer is set through a setter now
  • the intermediate writer pointer is gone. instead the ini is now constructed in the same scope as the regular data
  • to facilitate the former the MetadataINIWriter now tracks its writability so that the outside may judge whether it is worth using (this is effectively replacing writer=nullptr scenarios)
  • MetadataINIWriter's ctor has also been made slightly more robust as it now no longer accepts fd<-1 as "valid" states. instead all not explicitly handled conditions are considered unreachable

Merge request reports