fix: fixed memory leak on exit
This commit is contained in:
parent
9b8539e1e0
commit
81a1c7447c
3 changed files with 25 additions and 1 deletions
21
imap.c
21
imap.c
|
|
@ -74,6 +74,20 @@ void imap_populate_trie(void)
|
|||
|
||||
#define CMD_MAP_LAST 0x5
|
||||
|
||||
void imap_trie_free(trie_node *node)
|
||||
{
|
||||
trie_node *tmp = NULL;
|
||||
|
||||
for (int i=0; i < 26; i++) {
|
||||
tmp = node->children[i];
|
||||
if (tmp != NULL) {
|
||||
imap_trie_free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
free(node);
|
||||
}
|
||||
|
||||
uint8_t imap_init(uint8_t daemon, imap_t *instance)
|
||||
{
|
||||
imap_populate_trie();
|
||||
|
|
@ -316,14 +330,21 @@ void imap_close(imap_t *instance)
|
|||
client_list *node = instance->clients;
|
||||
client_list *tmp = node;
|
||||
while (node != NULL) {
|
||||
if (instance->ssl) {
|
||||
SSL_shutdown(node->ssl);
|
||||
SSL_free(node->ssl);
|
||||
}
|
||||
close(node->socket);
|
||||
tmp = node->next;
|
||||
free(node);
|
||||
node = tmp;
|
||||
}
|
||||
|
||||
imap_trie_free(trie);
|
||||
close(instance->socket);
|
||||
if (instance->ssl) {
|
||||
SSL_CTX_free(instance->ssl_ctx);
|
||||
}
|
||||
free(instance);
|
||||
}
|
||||
|
||||
|
|
|
|||
1
imap.h
1
imap.h
|
|
@ -94,5 +94,6 @@ void imap_flush(client_list *node, uint8_t ssl);
|
|||
uint8_t imap_cmd_exec(imap_cmd cmd, client_list *node, uint8_t ssl, uint8_t state);
|
||||
void imap_trie_populate(void);
|
||||
void imap_trie_encode(char *str, uint8_t cmd);
|
||||
void imap_trie_free(trie_node *node);
|
||||
|
||||
#endif /* ifndef IMAP_H */
|
||||
|
|
|
|||
2
sis.c
2
sis.c
|
|
@ -39,6 +39,8 @@ void int_handler(int sig)
|
|||
if (instance != NULL) {
|
||||
imap_close(instance);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue