History

avio: add a destructor for AVIOContext

Before this commit, AVIOContext is to be freed with a plain av_free(), which prevents us from adding any deeper structure to it. (cherry picked from commit 99684f3ae752fc8bfb44a2dd1482f8d7a3d8536d) Signed-off-by: James Almer <jamrial@gmail.com>

Anton Khirnov committed 9 years ago

Commit b12e4d31 parent 837580f4 files · +26 −4Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavformat/avio.h +8 −0
  3. libavformat/aviobuf.c +14 −3
  4. libavformat/version.h +1 −1
doc/APIchanges+3−0
@@ -15,6 +15,9 @@ libavutil: 2015-08-28 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2017-09-01 - xxxxxxx - lavf 57.80.100 / 57.11.0 - avio.h
19+ Add avio_context_free(). From now on it must be used for freeing AVIOContext.
20+
1821 2017-08-08 - xxxxxxx - lavu 55.74.100 - pixdesc.h
1922 Add AV_PIX_FMT_FLAG_FLOAT pixel format flag.
2023
libavformat/avio.h+8−0
@@ -467,6 +467,14 @@ AVIOContext *avio_alloc_context( · 466 unmodified lines
467467 int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
468468 int64_t (*seek)(void *opaque, int64_t offset, int whence));
469469
470+/**
471+ * Free the supplied IO context and everything associated with it.
472+ *
473+ * @param s Double pointer to the IO context. This function will write NULL
474+ * into s.
475+ */
476+void avio_context_free(AVIOContext **s);
477+
470478 void avio_w8(AVIOContext *s, int b);
471479 void avio_write(AVIOContext *s, const unsigned char *buf, int size);
472480 void avio_wl64(AVIOContext *s, uint64_t val);
libavformat/aviobuf.c+14−3
@@ -143,6 +143,11 @@ AVIOContext *avio_alloc_context( · 142 unmodified lines
143143 return s;
144144 }
145145
146+void avio_context_free(AVIOContext **ps)
147+{
148+ av_freep(ps);
149+}
150+
146151 static void writeout(AVIOContext *s, const uint8_t *data, int len)
147152 {
148153 if (!s->error) {
@@ -1123,7 +1128,9 @@ int avio_close(AVIOContext *s) · 974 unmodified lines
11231128 else
11241129 av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
11251130 av_opt_free(s);
1126− av_free(s);
1131+
1132+ avio_context_free(&s);
1133+
11271134 return ffurl_close(h);
11281135 }
11291136
@@ -1356,7 +1363,9 @@ int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) · 226 unmodified lines
13561363 *pbuffer = d->buffer;
13571364 size = d->size;
13581365 av_free(d);
1359− av_free(s);
1366+
1367+ avio_context_free(&s);
1368+
13601369 return size - padding;
13611370 }
13621371
@@ -1399,6 +1408,8 @@ int ffio_close_null_buf(AVIOContext *s) · 36 unmodified lines
13991408
14001409 size = d->size;
14011410 av_free(d);
1402− av_free(s);
1411+
1412+ avio_context_free(&s);
1413+
14031414 return size;
14041415 }
libavformat/version.h+1−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium)
3333 // Also please add any ticket numbers that you believe might be affected here
3434 #define LIBAVFORMAT_VERSION_MAJOR 57
35−#define LIBAVFORMAT_VERSION_MINOR 79
35+#define LIBAVFORMAT_VERSION_MINOR 80
3636 #define LIBAVFORMAT_VERSION_MICRO 100
3737
3838 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t