From 954fc854f23740bf2b87240474cbc3c391449916 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 26 Dec 2014 01:13:49 +0100 Subject: [PATCH] avformat/cache: cleanup cache file on cache write failure Signed-off-by: Michael Niedermayer --- libavformat/cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavformat/cache.c b/libavformat/cache.c index 0746e98d3e..29b4a0687f 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -92,7 +92,7 @@ static int cache_open(URLContext *h, const char *arg, int flags) static int add_entry(URLContext *h, const unsigned char *buf, int size) { Context *c= h->priv_data; - int64_t pos; + int64_t pos = -1; int ret; CacheEntry *entry = av_malloc(sizeof(*entry)); CacheEntry *entry_ret; @@ -132,6 +132,8 @@ static int add_entry(URLContext *h, const unsigned char *buf, int size) return 0; fail: + if (pos >= 0) + ftruncate(c->fd, pos); av_free(entry); av_free(node); return ret;