Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
95d47436
Unverified
Commit
95d47436
authored
Jan 06, 2024
by
Wolle
Committed by
GitHub
Jan 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memory leak in the Vorbis Decoder #623
parent
6b1e6dcc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
41 deletions
+55
-41
src/vorbis_decoder/vorbis_decoder.cpp
src/vorbis_decoder/vorbis_decoder.cpp
+53
-40
src/vorbis_decoder/vorbis_decoder.h
src/vorbis_decoder/vorbis_decoder.h
+2
-1
No files found.
src/vorbis_decoder/vorbis_decoder.cpp
View file @
95d47436
...
...
@@ -15,7 +15,7 @@
* adapted for the ESP32 by schreibfaul1
*
* Created on: 13.02.2023
* Updated on:
29.12
.2023
* Updated on:
06.01
.2023
*/
//----------------------------------------------------------------------------------------------------------------------
// O G G I M P L.
...
...
@@ -93,42 +93,7 @@ void VORBISDecoder_FreeBuffers(){
if
(
s_vorbisChbuf
){
free
(
s_vorbisChbuf
);
s_vorbisChbuf
=
NULL
;}
if
(
s_lastSegmentTable
){
free
(
s_lastSegmentTable
);
s_lastSegmentTable
=
NULL
;}
if
(
s_nrOfMaps
)
{
for
(
int
i
=
0
;
i
<
s_nrOfMaps
;
i
++
)
/* unpack does the range checking */
mapping_clear_info
(
s_map_param
+
i
);
s_nrOfMaps
=
0
;
}
if
(
s_nrOfFloors
)
{
for
(
int
i
=
0
;
i
<
s_nrOfFloors
;
i
++
)
/* unpack does the range checking */
floor_free_info
(
s_floor_param
[
i
]);
free
(
s_floor_param
);
s_nrOfFloors
=
0
;
}
if
(
s_nrOfResidues
)
{
for
(
int
i
=
0
;
i
<
s_nrOfResidues
;
i
++
)
/* unpack does the range checking */
res_clear_info
(
s_residue_param
+
i
);
s_nrOfResidues
=
0
;
}
if
(
s_nrOfCodebooks
)
{
for
(
int
i
=
0
;
i
<
s_nrOfCodebooks
;
i
++
)
vorbis_book_clear
(
s_codebooks
+
i
);
s_nrOfCodebooks
=
0
;
}
if
(
s_codebooks
)
{
free
(
s_codebooks
);
s_codebooks
=
NULL
;}
if
(
s_floor_type
){
free
(
s_floor_type
);
s_floor_type
=
NULL
;}
if
(
s_residue_param
){
free
(
s_residue_param
);
s_residue_param
=
NULL
;}
if
(
s_map_param
){
free
(
s_map_param
);
s_map_param
=
NULL
;}
if
(
s_mode_param
)
{
free
(
s_mode_param
);
s_mode_param
=
NULL
;}
if
(
s_dsp_state
){
vorbis_dsp_destroy
(
s_dsp_state
);
s_dsp_state
=
NULL
;}
clearGlobalConfigurations
();
}
void
VORBISDecoder_ClearBuffers
(){
if
(
s_vorbisChbuf
)
memset
(
s_vorbisChbuf
,
0
,
256
);
...
...
@@ -161,6 +126,50 @@ void VORBISsetDefaults(){
VORBISDecoder_ClearBuffers
();
}
void
clearGlobalConfigurations
()
{
// mode, mapping, floor etc
if
(
s_nrOfCodebooks
)
{
// if we have a stream with changing codebooks, delete the old one
for
(
int
i
=
0
;
i
<
s_nrOfCodebooks
;
i
++
)
{
vorbis_book_clear
(
s_codebooks
+
i
);
}
s_nrOfCodebooks
=
0
;
}
if
(
s_codebooks
)
{
free
(
s_codebooks
);
s_codebooks
=
NULL
;
}
if
(
s_dsp_state
)
{
vorbis_dsp_destroy
(
s_dsp_state
);
s_dsp_state
=
NULL
;
}
if
(
s_nrOfFloors
)
{
for
(
int
i
=
0
;
i
<
s_nrOfFloors
;
i
++
)
floor_free_info
(
s_floor_param
[
i
]);
free
(
s_floor_param
);
s_nrOfFloors
=
0
;
}
if
(
s_nrOfResidues
)
{
for
(
int
i
=
0
;
i
<
s_nrOfResidues
;
i
++
)
res_clear_info
(
s_residue_param
+
i
);
s_nrOfResidues
=
0
;
}
if
(
s_nrOfMaps
)
{
for
(
int
i
=
0
;
i
<
s_nrOfMaps
;
i
++
)
{
mapping_clear_info
(
s_map_param
+
i
);
}
s_nrOfMaps
=
0
;
}
if
(
s_floor_type
)
{
free
(
s_floor_type
);
s_floor_type
=
NULL
;
}
if
(
s_residue_param
)
{
free
(
s_residue_param
);
s_residue_param
=
NULL
;
}
if
(
s_map_param
)
{
free
(
s_map_param
);
s_map_param
=
NULL
;
}
if
(
s_mode_param
)
{
free
(
s_mode_param
);
s_mode_param
=
NULL
;
}
}
//----------------------------------------------------------------------------------------------------------------------
int
VORBISDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
){
...
...
@@ -190,7 +199,8 @@ int VORBISDecode(uint8_t *inbuf, int *bytesLeft, short *outbuf){
}
if
(
s_pageNr
==
1
){
// identificaton header
int
idx
=
VORBIS_specialIndexOf
(
inbuf
,
"vorbis"
,
10
);
clearGlobalConfigurations
();
// if a new codebook is required, delete the old one
int
idx
=
VORBIS_specialIndexOf
(
inbuf
,
"vorbis"
,
10
);
if
(
idx
==
1
){
// log_i("first packet (identification len) %i", len);
s_identificatonHeaderLength
=
len
;
...
...
@@ -936,12 +946,14 @@ int vorbis_book_unpack(codebook_t *s) {
goto
_errout
;
}
if
(
oggpack_eop
())
goto
_eofout
;
if
(
lengthlist
)
free
(
lengthlist
);
if
(
lengthlist
)
{
free
(
lengthlist
);
lengthlist
=
NULL
;}
if
(
s
->
q_val
)
{
free
(
s
->
q_val
),
s
->
q_val
=
NULL
;}
return
0
;
// ok
_errout:
_eofout:
vorbis_book_clear
(
s
);
if
(
lengthlist
)
free
(
lengthlist
);
if
(
lengthlist
)
{
free
(
lengthlist
);
lengthlist
=
NULL
;}
if
(
s
->
q_val
)
{
free
(
s
->
q_val
),
s
->
q_val
=
NULL
;}
return
-
1
;
// error
}
//---------------------------------------------------------------------------------------------------------------------
...
...
@@ -1690,6 +1702,7 @@ void vorbis_dsp_destroy(vorbis_dsp_state_t *v) {
if
(
v
->
mdctright
){
free
(
v
->
mdctright
);
v
->
mdctright
=
NULL
;}
}
free
(
v
);
v
=
NULL
;
}
}
//---------------------------------------------------------------------------------------------------------------------
...
...
src/vorbis_decoder/vorbis_decoder.h
View file @
95d47436
...
...
@@ -20,7 +20,7 @@
* adapted for the ESP32 by schreibfaul1
*
* Created on: 13.02.2023
* Updated on: 0
3.12
.2023
* Updated on: 0
6.01
.2023
*/
...
...
@@ -220,6 +220,7 @@ bool VORBISDecoder_AllocateBuffers();
void
VORBISDecoder_FreeBuffers
();
void
VORBISDecoder_ClearBuffers
();
void
VORBISsetDefaults
();
void
clearGlobalConfigurations
();
int
VORBISDecode
(
uint8_t
*
inbuf
,
int
*
bytesLeft
,
short
*
outbuf
);
uint8_t
VORBISGetChannels
();
uint32_t
VORBISGetSampRate
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment