diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2017-10-14 05:59:09 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2017-10-14 06:07:09 -0400 |
commit | 81f5a225f7ce37694b7d93cc9ce20bf1fa706a3a (patch) | |
tree | d6954306d9476bce56b531048cedb9056ade142e /apps | |
parent | a8e4b3a1906f05f6ab7fc1ee94e0be513cb2c86a (diff) | |
download | rockbox-81f5a225f7ce37694b7d93cc9ce20bf1fa706a3a.tar.gz rockbox-81f5a225f7ce37694b7d93cc9ce20bf1fa706a3a.zip |
Fix plugin core_alloc_maximum functionality
One mustn't assume a plugin will only call plugin_get_audio_buffer one
time or that the buffer_size pointer is always non-NULL. At least one
plugin, pacbox, will call it each time it (re)starts audio, with a NULL
param (which is intentional because it only wants to kill audio
playback), and leak away all the RAM because the handle gets clobbered
by further calls and the memory can't be released.
Change-Id: Ic5b94dbc0277c42964ea85b4e9d0302a7c6f1fe4
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugin.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/apps/plugin.c b/apps/plugin.c index d14b6468e0..33a46a3d84 100644 --- a/apps/plugin.c +++ b/apps/plugin.c | |||
@@ -841,6 +841,7 @@ static const struct plugin_api rockbox_api = { | |||
841 | }; | 841 | }; |
842 | 842 | ||
843 | static int plugin_buffer_handle; | 843 | static int plugin_buffer_handle; |
844 | static size_t plugin_buffer_size; | ||
844 | 845 | ||
845 | int plugin_load(const char* plugin, const void* parameter) | 846 | int plugin_load(const char* plugin, const void* parameter) |
846 | { | 847 | { |
@@ -1018,15 +1019,26 @@ static void* plugin_get_audio_buffer(size_t *buffer_size) | |||
1018 | /* dummy ops with no callbacks, needed because by | 1019 | /* dummy ops with no callbacks, needed because by |
1019 | * default buflib buffers can be moved around which must be avoided */ | 1020 | * default buflib buffers can be moved around which must be avoided */ |
1020 | static struct buflib_callbacks dummy_ops; | 1021 | static struct buflib_callbacks dummy_ops; |
1021 | plugin_buffer_handle = core_alloc_maximum("plugin audio buf", buffer_size, | 1022 | if (plugin_buffer_handle <= 0) |
1022 | &dummy_ops); | 1023 | { |
1024 | plugin_buffer_handle = core_alloc_maximum("plugin audio buf", | ||
1025 | &plugin_buffer_size, | ||
1026 | &dummy_ops); | ||
1027 | } | ||
1028 | |||
1029 | if (buffer_size) | ||
1030 | *buffer_size = plugin_buffer_size; | ||
1031 | |||
1023 | return core_get_data(plugin_buffer_handle); | 1032 | return core_get_data(plugin_buffer_handle); |
1024 | } | 1033 | } |
1025 | 1034 | ||
1026 | static void plugin_release_audio_buffer(void) | 1035 | static void plugin_release_audio_buffer(void) |
1027 | { | 1036 | { |
1028 | if (plugin_buffer_handle > 0) | 1037 | if (plugin_buffer_handle > 0) |
1038 | { | ||
1029 | plugin_buffer_handle = core_free(plugin_buffer_handle); | 1039 | plugin_buffer_handle = core_free(plugin_buffer_handle); |
1040 | plugin_buffer_size = 0; | ||
1041 | } | ||
1030 | } | 1042 | } |
1031 | 1043 | ||
1032 | /* The plugin wants to stay resident after leaving its main function, e.g. | 1044 | /* The plugin wants to stay resident after leaving its main function, e.g. |