Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
955a6388
Commit
955a6388
authored
Nov 04, 2018
by
devsaurus
Browse files
i2s: fix memory leak for pending tx data when node_i2s_stop() deletes the tx task
parent
bf549a24
Changes
1
Hide whitespace changes
Inline
Side-by-side
components/modules/i2s.c
View file @
955a6388
...
@@ -104,7 +104,9 @@ static void task_I2S_tx( void *pvParameters ) {
...
@@ -104,7 +104,9 @@ static void task_I2S_tx( void *pvParameters ) {
task_post_high
(
i2s_tx_task_id
,
i2s_id
);
task_post_high
(
i2s_tx_task_id
,
i2s_id
);
// get TX data from Lua task
// get TX data from Lua task
xQueueReceive
(
is
->
tx
.
queue
,
&
tx_data
,
portMAX_DELAY
);
// just peek the item to keep it in the queue so that node_i2s_stop can find and unref it if
// this task was deleted before posting i2s_disposal_task
xQueuePeek
(
is
->
tx
.
queue
,
&
tx_data
,
portMAX_DELAY
);
// write TX data to I2S, note that this call might block
// write TX data to I2S, note that this call might block
size_t
dummy
;
size_t
dummy
;
...
@@ -116,6 +118,8 @@ static void task_I2S_tx( void *pvParameters ) {
...
@@ -116,6 +118,8 @@ static void task_I2S_tx( void *pvParameters ) {
// notify Lua to dispose object
// notify Lua to dispose object
task_post_low
(
i2s_disposal_task_id
,
tx_data
.
ref
);
task_post_low
(
i2s_disposal_task_id
,
tx_data
.
ref
);
// tx data is going to be unref'ed, so finally remove it from the queue
xQueueReceive
(
is
->
tx
.
queue
,
&
tx_data
,
portMAX_DELAY
);
}
}
}
}
...
@@ -237,13 +241,17 @@ static int node_i2s_stop( lua_State *L )
...
@@ -237,13 +241,17 @@ static int node_i2s_stop( lua_State *L )
I2S_CHECK_ID
(
i2s_id
);
I2S_CHECK_ID
(
i2s_id
);
i2s_status_t
*
is
=
&
i2s_status
[
i2s_id
];
i2s_status_t
*
is
=
&
i2s_status
[
i2s_id
];
i2s_driver_uninstall
(
i2s_id
);
if
(
is
->
tx
.
taskHandle
!=
NULL
)
{
if
(
is
->
tx
.
taskHandle
!=
NULL
)
{
vTaskDelete
(
is
->
tx
.
taskHandle
);
vTaskDelete
(
is
->
tx
.
taskHandle
);
is
->
tx
.
taskHandle
=
NULL
;
is
->
tx
.
taskHandle
=
NULL
;
}
}
if
(
is
->
tx
.
queue
!=
NULL
)
{
if
(
is
->
tx
.
queue
!=
NULL
)
{
// unlink pending tx jobs from the queue
while
(
uxQueueMessagesWaiting
(
is
->
tx
.
queue
)
>
0
)
{
i2s_tx_data_t
tx_data
;
xQueueReceive
(
is
->
tx
.
queue
,
&
tx_data
,
portMAX_DELAY
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
tx_data
.
ref
);
}
vQueueDelete
(
is
->
tx
.
queue
);
vQueueDelete
(
is
->
tx
.
queue
);
is
->
tx
.
queue
=
NULL
;
is
->
tx
.
queue
=
NULL
;
}
}
...
@@ -252,7 +260,9 @@ static int node_i2s_stop( lua_State *L )
...
@@ -252,7 +260,9 @@ static int node_i2s_stop( lua_State *L )
vTaskDelete
(
is
->
rx
.
taskHandle
);
vTaskDelete
(
is
->
rx
.
taskHandle
);
is
->
rx
.
taskHandle
=
NULL
;
is
->
rx
.
taskHandle
=
NULL
;
}
}
// the rx queue is created and destroyed by the I2S driver
// the rx queue is created and destroyed by the I2S driver
i2s_driver_uninstall
(
i2s_id
);
if
(
is
->
cb
!=
LUA_NOREF
)
{
if
(
is
->
cb
!=
LUA_NOREF
)
{
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
is
->
cb
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
is
->
cb
);
...
...
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