History

avcodec/wavpack: Fix leak and segfault on reallocation error

av_realloc_f() frees the buffer it is given on allocation failure. But in this case, the buffer is an array of ownership pointers, causing leaks on error. Furthermore, the count of pointers is unchanged on error and the codec's close function uses it to free said ownership pointers, causing a NPD. This is a regression since 46412a8935e4632b2460988bfce4152c7dccce22. Fix this by switching to av_realloc_array().

Andreas Rheinhardt committed 2 years ago

Commit 2f596481 parent a4800641 file · +4 −2Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/wavpack.c+4−2
@@ -973,9 +973,11 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, · 972 unmodified lines
973 973
974static av_cold int wv_alloc_frame_context(WavpackContext *c)974static av_cold int wv_alloc_frame_context(WavpackContext *c)
975{975{
976 c->fdec = av_realloc_f(c->fdec, c->fdec_num + 1, sizeof(*c->fdec));976 WavpackFrameContext **fdec = av_realloc_array(c->fdec, c->fdec_num + 1, sizeof(*c->fdec));
977 if (!c->fdec)977
978 if (!fdec)
978 return -1;979 return -1;
980 c->fdec = fdec;
979 981
980 c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));982 c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
981 if (!c->fdec[c->fdec_num])983 if (!c->fdec[c->fdec_num])

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