Monkey: Clean up various leaked blocks

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2019-09-07 15:24:37 +01:00
parent b03786920a
commit 8b0aec4bac
3 changed files with 23 additions and 1 deletions

View File

@ -29,7 +29,7 @@
typedef struct cmdhandler {
struct cmdhandler *r_next, *r_prev;
const char *cmd;
char *cmd;
handle_command_fn fn;
} monkey_cmdhandler_t;
@ -49,6 +49,17 @@ monkey_register_handler(const char *cmd, handle_command_fn fn)
return NSERROR_OK;
}
void
monkey_free_handlers(void)
{
while (handler_ring != NULL) {
monkey_cmdhandler_t *handler = handler_ring;
RING_REMOVE(handler_ring, handler);
free(handler->cmd);
free(handler);
}
}
void
monkey_process_command(void)
{

View File

@ -25,4 +25,6 @@ nserror monkey_register_handler(const char *cmd, handle_command_fn fn);
void monkey_process_command(void);
void monkey_free_handlers(void);
#endif /* NETSURF_MONKEY_DISPATCH_H */

View File

@ -380,6 +380,12 @@ main(int argc, char **argv)
urldb_load(nsoption_charp(url_file));
urldb_load_cookies(nsoption_charp(cookie_file));
/* Free resource paths now we're done finding resources */
for (char **s = respaths; *s != NULL; s++) {
free(*s);
}
free(respaths);
ret = monkey_register_handler("QUIT", quit_handler);
if (ret != NSERROR_OK) {
die("quit handler failed to register");
@ -421,5 +427,8 @@ main(int argc, char **argv)
/* finalise logging */
nslog_finalise();
/* And free any monkey-specific bits */
monkey_free_handlers();
return 0;
}