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

[ashell] Adding code to free cb memory and change cleanup order #742

Merged
merged 3 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ashell/jerry-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ void javascript_stop()
parsed_code = 0;

/* Cleanup engine */
zjs_ipm_free_callbacks();
zjs_modules_cleanup();
zjs_remove_all_callbacks();
zjs_ipm_free_callbacks();
jerry_cleanup();

restore_zjs_api();
Expand Down
9 changes: 9 additions & 0 deletions src/zjs_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ void zjs_remove_callback(zjs_callback_id id)
}
}

void zjs_remove_all_callbacks()
{
for (int i = 0; i < cb_size; i++) {
if (cb_map[i]) {
zjs_remove_callback(i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code clean up the ringbuffer? maybe @jprestwo can take a look here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, but I don't think ring buffer was the issue I was seeing. cb_map was the item making zjs_malloc calls. Not saying ring buffer couldn't also be an issue however.

}
}
}

void zjs_signal_callback(zjs_callback_id id, const void *args, uint32_t size)
{
DBG_PRINT("pushing item to ring buffer. id=%d, args=%p, size=%lu\n", id,
Expand Down
5 changes: 5 additions & 0 deletions src/zjs_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ void zjs_edit_callback_handle(zjs_callback_id id, void* handle);
*/
void zjs_remove_callback(zjs_callback_id id);

/*
* Remove all callbacks from memory
*/
void zjs_remove_all_callbacks();

/*
* Signal the system to make a callback. The callback will not be called
* immediately, but rather once the system has time to service the callback
Expand Down
4 changes: 3 additions & 1 deletion src/zjs_modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ void zjs_modules_init()

void zjs_modules_cleanup()
{
// stop timers first to prevent further calls
zjs_timers_cleanup();

int modcount = sizeof(zjs_modules_array) / sizeof(module_t);
for (int i = 0; i < modcount; i++) {
module_t *mod = &zjs_modules_array[i];
Expand All @@ -256,7 +259,6 @@ void zjs_modules_cleanup()

// clean up fixed modules
zjs_error_cleanup();
zjs_timers_cleanup();
#ifdef BUILD_MODULE_CONSOLE
zjs_console_cleanup();
#endif
Expand Down