Skip to content

Commit

Permalink
Return early in yaml_emitter_close
Browse files Browse the repository at this point in the history
If yaml_emitter_dump failed, the emitter might be in a broken
state and have leftover states/events.
yaml_emitter_close calls yaml_emitter_emit which will
try to emit those events, so we should return early.

The recommended thing to do for library users is to abort
when yaml_emitter_dump fails, but it's easy to add a check
here as well.
  • Loading branch information
perlpunk committed May 6, 2024
1 parent abd744e commit e584022
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/dumper.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ yaml_emitter_close(yaml_emitter_t *emitter)
assert(emitter->opened); /* Emitter should be opened. */

if (emitter->closed) return 1;
if (emitter->error) return 0; /* Emitter might have leftover events */

STREAM_END_EVENT_INIT(event, mark, mark);

Expand Down

0 comments on commit e584022

Please sign in to comment.