History

dict.c: Free non-strduped av_dict_set arguments on error.

Unfortunately this was not explicitly documented and thus might be risky. But all uses I could find in FFmpeg and one in VLC had a memleak in these cases, and I could not find any that relied on the previous behaviour.

Reimar Döffinger committed 12 years ago

Commit 8fc9bd01 parent 45c7f394 files · +13 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +5 −0
  2. libavutil/dict.c +2 −0
  3. libavutil/dict.h +5 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+5−0
@@ -15,6 +15,11 @@ libavutil: 2014-08-09 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2014-08-23 - xxxxxxx - lavu 54.7.100 - dict.h
19+ AV_DICT_DONT_STRDUP_KEY and AV_DICT_DONT_STRDUP_VAL arguments are now
20+ freed even on error. This is consistent with the behaviour all users
21+ of it we could find expect.
22+
1823 2014-08-21 - 980a5b0 - lavu 54.6.100 - frame.h motion_vector.h
1924 Add AV_FRAME_DATA_MOTION_VECTORS side data and AVMotionVector structure
2025
libavutil/dict.c+2−0
@@ -126,6 +126,8 @@ err_out: · 125 unmodified lines
126126 av_free(m->elems);
127127 av_freep(pm);
128128 }
129+ if (flags & AV_DICT_DONT_STRDUP_KEY) av_free(key);
130+ if (flags & AV_DICT_DONT_STRDUP_VAL) av_free(value);
129131 return AVERROR(ENOMEM);
130132 }
131133
libavutil/dict.h+5−0
@@ -115,6 +115,9 @@ int av_dict_count(const AVDictionary *m); · 114 unmodified lines
115115 /**
116116 * Set the given entry in *pm, overwriting an existing entry.
117117 *
118+ * Note: If AV_DICT_DONT_STRDUP_KEY or AV_DICT_DONT_STRDUP_VAL is set,
119+ * these arguments will be freed on error.
120+ *
118121 * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL
119122 * a dictionary struct is allocated and put in *pm.
120123 * @param key entry key to add to *pm (will be av_strduped depending on flags)
@@ -127,6 +130,8 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags · 6 unmodified lines
127130 /**
128131 * Convenience wrapper for av_dict_set that converts the value to a string
129132 * and stores it.
133+ *
134+ * Note: If AV_DICT_DONT_STRDUP_KEY is set, key will be freed on error.
130135 */
131136 int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags);
132137
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
5656 */
5757
5858 #define LIBAVUTIL_VERSION_MAJOR 54
59−#define LIBAVUTIL_VERSION_MINOR 6
59+#define LIBAVUTIL_VERSION_MINOR 7
6060 #define LIBAVUTIL_VERSION_MICRO 100
6161
6262 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_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