Skip to content

Commit 3a0d3a2

Browse files
committed
Return early in yaml_emitter_close
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.
1 parent 840b65c commit 3a0d3a2

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/dumper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ yaml_emitter_close(yaml_emitter_t *emitter)
9292
assert(emitter->opened); /* Emitter should be opened. */
9393

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

9697
STREAM_END_EVENT_INIT(event, mark, mark);
9798

0 commit comments

Comments
 (0)