Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit df5920d

Browse files
brianjjonesgrgustaf
authored andcommitted
[ashell] Adding code to free cb memory and change cleanup order (#742)
This adds a method that ensures all callbacks are freed. It also changes the order of some of the cleanup functions to ensure stability when starting / stopping apps using ashell. Signed-off-by: Brian J Jones <[email protected]>
1 parent f8e8c4b commit df5920d

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/ashell/jerry-code.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ void javascript_stop()
149149
parsed_code = 0;
150150

151151
/* Cleanup engine */
152-
zjs_ipm_free_callbacks();
153152
zjs_modules_cleanup();
153+
zjs_remove_all_callbacks();
154+
zjs_ipm_free_callbacks();
154155
jerry_cleanup();
155156

156157
restore_zjs_api();

src/zjs_callbacks.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ void zjs_remove_callback(zjs_callback_id id)
326326
}
327327
}
328328

329+
void zjs_remove_all_callbacks()
330+
{
331+
for (int i = 0; i < cb_size; i++) {
332+
if (cb_map[i]) {
333+
zjs_remove_callback(i);
334+
}
335+
}
336+
}
337+
329338
void zjs_signal_callback(zjs_callback_id id, const void *args, uint32_t size)
330339
{
331340
DBG_PRINT("pushing item to ring buffer. id=%d, args=%p, size=%lu\n", id,

src/zjs_callbacks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ void zjs_edit_callback_handle(zjs_callback_id id, void* handle);
147147
*/
148148
void zjs_remove_callback(zjs_callback_id id);
149149

150+
/*
151+
* Remove all callbacks from memory
152+
*/
153+
void zjs_remove_all_callbacks();
154+
150155
/*
151156
* Signal the system to make a callback. The callback will not be called
152157
* immediately, but rather once the system has time to service the callback

src/zjs_modules.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ void zjs_modules_init()
242242

243243
void zjs_modules_cleanup()
244244
{
245+
// stop timers first to prevent further calls
246+
zjs_timers_cleanup();
247+
245248
int modcount = sizeof(zjs_modules_array) / sizeof(module_t);
246249
for (int i = 0; i < modcount; i++) {
247250
module_t *mod = &zjs_modules_array[i];
@@ -256,7 +259,6 @@ void zjs_modules_cleanup()
256259

257260
// clean up fixed modules
258261
zjs_error_cleanup();
259-
zjs_timers_cleanup();
260262
#ifdef BUILD_MODULE_CONSOLE
261263
zjs_console_cleanup();
262264
#endif

0 commit comments

Comments
 (0)