From c4aa669cf19b64703d525753c0c736beee56d0e3 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 23 Apr 2017 23:24:48 -0700 Subject: [PATCH] Core: Fix flushing a read video log --- src/feature/video-logger.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/feature/video-logger.c b/src/feature/video-logger.c index 57a028c3c..6697cf9bb 100644 --- a/src/feature/video-logger.c +++ b/src/feature/video-logger.c @@ -80,6 +80,7 @@ struct mVideoLogContext { uint32_t nChannels; struct mVideoLogChannel channels[mVL_MAX_CHANNELS]; + bool write; uint32_t activeChannel; struct VFile* backing; }; @@ -320,6 +321,8 @@ struct mVideoLogContext* mVideoLogContextCreate(struct mCore* core) { struct mVideoLogContext* context = malloc(sizeof(*context)); memset(context, 0, sizeof(*context)); + context->write = !!core; + if (core) { context->initialStateSize = core->stateSize(core); context->initialState = anonymousMemoryMap(context->initialStateSize); @@ -449,11 +452,13 @@ static void _flushBuffer(struct mVideoLogContext* context) { } void mVideoLogContextDestroy(struct mCore* core, struct mVideoLogContext* context) { - _flushBuffer(context); + if (context->write) { + _flushBuffer(context); - struct mVLBlockHeader header = { 0 }; - STORE_32LE(mVL_BLOCK_FOOTER, 0, &header.blockType); - context->backing->write(context->backing, &header, sizeof(header)); + struct mVLBlockHeader header = { 0 }; + STORE_32LE(mVL_BLOCK_FOOTER, 0, &header.blockType); + context->backing->write(context->backing, &header, sizeof(header)); + } if (core) { core->endVideoLog(core);