diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-22 16:04:03 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-22 16:04:03 +0100 |
commit | 1edfdc77b42d647384c7ef09e2a2b0a59e69633a (patch) | |
tree | d87b6f150ea69ff4be314ea54e85c7152880a9f1 | |
parent | d9ae2aff1dbefb80cdb64991ce60b7193ab16173 (diff) | |
download | libgnunetchat-1edfdc77b42d647384c7ef09e2a2b0a59e69633a.tar.gz libgnunetchat-1edfdc77b42d647384c7ef09e2a2b0a59e69633a.zip |
Added shutdown hook to cleanup memory leaks
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/gnunet_chat_handle.c | 6 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 2 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 14 |
3 files changed, 21 insertions, 1 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index b676cc9..92b4fbe 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -38,6 +38,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
38 | struct GNUNET_CHAT_Handle* handle = GNUNET_new(struct GNUNET_CHAT_Handle); | 38 | struct GNUNET_CHAT_Handle* handle = GNUNET_new(struct GNUNET_CHAT_Handle); |
39 | 39 | ||
40 | handle->cfg = cfg; | 40 | handle->cfg = cfg; |
41 | handle->shutdown_hook = GNUNET_SCHEDULER_add_shutdown( | ||
42 | on_handle_shutdown, handle | ||
43 | ); | ||
41 | 44 | ||
42 | if ((directory) && | 45 | if ((directory) && |
43 | (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES))) | 46 | (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES))) |
@@ -120,6 +123,9 @@ handle_destroy (struct GNUNET_CHAT_Handle* handle) | |||
120 | (handle->contexts) && | 123 | (handle->contexts) && |
121 | (handle->files)); | 124 | (handle->files)); |
122 | 125 | ||
126 | if (handle->shutdown_hook) | ||
127 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); | ||
128 | |||
123 | if (handle->public_key) | 129 | if (handle->public_key) |
124 | GNUNET_free(handle->public_key); | 130 | GNUNET_free(handle->public_key); |
125 | 131 | ||
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index dde11d2..ab7291e 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <gnunet/gnunet_arm_service.h> | 32 | #include <gnunet/gnunet_arm_service.h> |
33 | #include <gnunet/gnunet_fs_service.h> | 33 | #include <gnunet/gnunet_fs_service.h> |
34 | #include <gnunet/gnunet_messenger_service.h> | 34 | #include <gnunet/gnunet_messenger_service.h> |
35 | #include <gnunet/gnunet_scheduler_lib.h> | ||
35 | #include <gnunet/gnunet_util_lib.h> | 36 | #include <gnunet/gnunet_util_lib.h> |
36 | 37 | ||
37 | #include "gnunet_chat_lib.h" | 38 | #include "gnunet_chat_lib.h" |
@@ -39,6 +40,7 @@ | |||
39 | struct GNUNET_CHAT_Handle | 40 | struct GNUNET_CHAT_Handle |
40 | { | 41 | { |
41 | const struct GNUNET_CONFIGURATION_Handle* cfg; | 42 | const struct GNUNET_CONFIGURATION_Handle* cfg; |
43 | struct GNUNET_SCHEDULER_Task *shutdown_hook; | ||
42 | 44 | ||
43 | char *directory; | 45 | char *directory; |
44 | 46 | ||
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index d275aaf..6e158db 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -34,7 +34,19 @@ | |||
34 | #define GNUNET_UNUSED __attribute__ ((unused)) | 34 | #define GNUNET_UNUSED __attribute__ ((unused)) |
35 | 35 | ||
36 | void | 36 | void |
37 | on_handle_arm_connection(void *cls, int connected) | 37 | on_handle_shutdown(void *cls) |
38 | { | ||
39 | struct GNUNET_CHAT_Handle *chat = cls; | ||
40 | |||
41 | GNUNET_assert((chat) && (chat->shutdown_hook)); | ||
42 | chat->shutdown_hook = NULL; | ||
43 | |||
44 | handle_destroy(chat); | ||
45 | } | ||
46 | |||
47 | void | ||
48 | on_handle_arm_connection(void *cls, | ||
49 | int connected) | ||
38 | { | 50 | { |
39 | struct GNUNET_CHAT_Handle *chat = cls; | 51 | struct GNUNET_CHAT_Handle *chat = cls; |
40 | 52 | ||