diff options
author | Gyan Doshi <ffmpeg@gyani.pro> | 2019-05-22 18:05:04 +0530 |
---|---|---|
committer | Gyan Doshi <ffmpeg@gyani.pro> | 2019-05-25 00:21:26 +0530 |
commit | 50789e356d65270698d0d8495323ebe76a46091a (patch) | |
tree | 545682e84796adcf481e388e97102ea8672b6cf9 | |
parent | a6818d5bd0099de3f36406481b1672e430dacba5 (diff) | |
download | ffmpeg-50789e356d65270698d0d8495323ebe76a46091a.tar.gz |
avformat/cache - delete cache file after closing handle
Verified that cache files get deleted on Windows.
-rw-r--r-- | libavformat/cache.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libavformat/cache.c b/libavformat/cache.c index 66bbbf54c9..3425be9350 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -54,6 +54,7 @@ typedef struct CacheEntry { typedef struct Context { AVClass *class; int fd; + char *filename; struct AVTreeNode *root; int64_t logical_pos; int64_t cache_pos; @@ -72,6 +73,7 @@ static int cmp(const void *key, const void *node) static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options) { + int ret; char *buffername; Context *c= h->priv_data; @@ -83,8 +85,12 @@ static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary ** return c->fd; } - unlink(buffername); - av_freep(&buffername); + ret = unlink(buffername); + + if (ret >= 0) + av_freep(&buffername); + else + c->filename = buffername; return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h); @@ -292,11 +298,18 @@ static int enu_free(void *opaque, void *elem) static int cache_close(URLContext *h) { Context *c= h->priv_data; + int ret; av_log(h, AV_LOG_INFO, "Statistics, cache hits:%"PRId64" cache misses:%"PRId64"\n", c->cache_hit, c->cache_miss); close(c->fd); + if (c->filename) { + ret = unlink(c->filename); + if (ret < 0) + av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename); + av_freep(&c->filename); + } ffurl_close(c->inner); av_tree_enumerate(c->root, NULL, NULL, enu_free); av_tree_destroy(c->root); |