Merge pull request #15223 from ibrahn/ogg-data-leak-fix

free associated audio data on AudioStreamOGGVorbis destruction
This commit is contained in:
Rémi Verschelde 2018-01-04 15:25:20 +01:00 committed by GitHub
commit c4c1ca9cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -164,6 +164,14 @@ String AudioStreamOGGVorbis::get_stream_name() const {
return ""; //return stream_name; return ""; //return stream_name;
} }
void AudioStreamOGGVorbis::clear_data() {
if (data) {
AudioServer::get_singleton()->audio_data_free(data);
data = NULL;
data_len = 0;
}
}
void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) { void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
int src_data_len = p_data.size(); int src_data_len = p_data.size();
@ -209,6 +217,9 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
length = stb_vorbis_stream_length_in_seconds(ogg_stream); length = stb_vorbis_stream_length_in_seconds(ogg_stream);
stb_vorbis_close(ogg_stream); stb_vorbis_close(ogg_stream);
// free any existing data
clear_data();
data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr()); data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr());
data_len = src_data_len; data_len = src_data_len;
@ -275,3 +286,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
decode_mem_size = 0; decode_mem_size = 0;
loop = false; loop = false;
} }
AudioStreamOGGVorbis::~AudioStreamOGGVorbis() {
clear_data();
}

View File

@ -93,6 +93,7 @@ class AudioStreamOGGVorbis : public AudioStream {
float length; float length;
bool loop; bool loop;
float loop_offset; float loop_offset;
void clear_data();
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -111,6 +112,7 @@ public:
PoolVector<uint8_t> get_data() const; PoolVector<uint8_t> get_data() const;
AudioStreamOGGVorbis(); AudioStreamOGGVorbis();
virtual ~AudioStreamOGGVorbis();
}; };
#endif #endif