From 78f69152b58d9d265f6c34542e241f0e638bb5a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sat, 30 Apr 2022 16:10:58 +0200 Subject: testiral valgrind, clang, gcc, tcc, scan-build, 2 naenkrat, gdb --- ircxmpp.c | 32 ++++++++++++++++---------------- ircxmpp.h | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ircxmpp.c b/ircxmpp.c index d435797..302d164 100644 --- a/ircxmpp.c +++ b/ircxmpp.c @@ -63,12 +63,14 @@ static void free_bridge (struct bridge * bridge, const char * razlog) { LOG(bridge->ircxmpp, IRCXMPP_DEBUG, "freeing bridge with reason: %s", razlog); if (bridge->irc) { irc_cmd_quit(bridge->irc, razlog); - irc_run_once(bridge); // verjetno je to potrebno, da pošlje quit + if (strcmp(razlog, "free_bridge_from_tdestroy")) + irc_run_once(bridge); // verjetno je to potrebno, da pošlje quit irc_destroy_session(bridge->irc); } if (bridge->conn) xmpp_conn_release(bridge->conn); // graceful disconnect, what is that? - tdelete(bridge, bridge->ircxmpp->bridges, bridge_compare); + if (strcmp(razlog, "free_bridge_from_tdestroy")) + tdelete(bridge, bridge->ircxmpp->bridges, bridge_compare); free(bridge->identifier); for (size_t i = 0; i < bridge->messages_length; i++) free(bridge->messages[i]); @@ -76,13 +78,12 @@ static void free_bridge (struct bridge * bridge, const char * razlog) { free(bridge); } -static char * free_reason = "global readdson not set since startup. this is a bug. report it."; -static void free_bridge_global_reason (void * bridge) { - free_bridge((struct bridge *) bridge, free_reason); +static void free_bridge_from_tdestroy (void * bridge) { + free_bridge((struct bridge *) bridge, "free_bridge_from_tdestroy"); } static void free_bridges (void ** bridges) { - free_reason = "vsi mostovi se podirajo, ker se ircxmpp izklaplja"; - tdestroy(*bridges, free_bridge_global_reason); + tdestroy(*bridges, free_bridge_from_tdestroy); + *bridges = NULL; } static struct bridge * find_bridge (void ** bridges, const char * id, enum side side) { @@ -259,9 +260,8 @@ static void dump_event_control ( irc_session_t * s, const char * e, const char * o, const char ** p, unsigned c) { struct ircxmpp * ircxmpp = (struct ircxmpp *) irc_get_ctx(s); int requiredbuf = 256; - for (unsigned int i = 0; i < c; i++) { - requiredbuf += strlen(p[c])+256; - } + for (unsigned int i = 0; i < c; i++) + requiredbuf += strlen(p[i])+256; if (requiredbuf > 65535) return; char buf[requiredbuf]; @@ -272,7 +272,7 @@ static void dump_event_control ( cp += sprintf(cp, "|"); cp += sprintf(cp, "%s", p[i]); } - cp += sprintf(cp, "]"); + /* cp += */ sprintf(cp, "]"); ircxmpp->log_handler(ircxmpp->log_userdata, IRCXMPP_DEBUG, "irc_event_control", buf); } static void dump_event ( @@ -281,7 +281,7 @@ static void dump_event ( struct ircxmpp * ircxmpp = bridge->ircxmpp; int requiredbuf = 256; for (unsigned int i = 0; i < c; i++) { - requiredbuf += strlen(p[c])+256; + requiredbuf += strlen(p[i])+256; } if (requiredbuf > 65535) return; @@ -293,7 +293,7 @@ static void dump_event ( cp += sprintf(cp, "|"); cp += sprintf(cp, "%s", p[i]); } - cp += sprintf(cp, "]"); + /* cp += */ sprintf(cp, "]"); ircxmpp->log_handler(ircxmpp->log_userdata, IRCXMPP_DEBUG, "irc_event", buf); } static void event_connect ( @@ -562,7 +562,7 @@ static void init_irc_control (struct ircxmpp * ircxmpp) { irc_run_once_control(ircxmpp); return; } -static void ircxmpp_default_logger (void * const u __attribute__((unused)), +static void default_log_handler (void * const u __attribute__((unused)), const enum ircxmpp_loglevel l, const char * const a, const char * const m) { char * t = "unspec"; switch (l) { @@ -605,14 +605,14 @@ static void send_xmpp_logs_to_me (void * const u, const xmpp_log_level_t l, cons struct ircxmpp * ircxmpp_init (void) { xmpp_initialize(); struct ircxmpp * ircxmpp = calloc(1, sizeof(struct ircxmpp)); - ircxmpp->log_handler = ircxmpp_default_logger; + ircxmpp->log_handler = default_log_handler; ircxmpp->xmpp_logger.handler = send_xmpp_logs_to_me; ircxmpp->xmpp_logger.userdata = ircxmpp; return ircxmpp; } void ircxmpp_set_log_handler (struct ircxmpp * ircxmpp, ircxmpp_logger log_handler) { if (!log_handler) - ircxmpp->log_handler = ircxmpp_default_logger; + ircxmpp->log_handler = default_log_handler; ircxmpp->log_handler = log_handler; } void ircxmpp_set_log_userdata (struct ircxmpp * ircxmpp, void * log_userdata) { diff --git a/ircxmpp.h b/ircxmpp.h index 3ca5e03..29b4419 100644 --- a/ircxmpp.h +++ b/ircxmpp.h @@ -183,7 +183,7 @@ static void logwrite (struct ircxmpp *, enum ircxmpp_loglevel, const char *, int static int bridge_compare (const void *, const void *); static void free_bridge (struct bridge *, const char *); static void free_bridges (void **); -static void free_bridge_global_reason (void *); +static void free_bridge_from_tdestroy (void *); static struct bridge * find_bridge (void **, const char *, enum side); static void jid2ircnick (char *); static void jid2ircuser (char *); @@ -219,7 +219,7 @@ static int irc_run_once (struct bridge *); static void init_irc (struct bridge *); static void init_irc_control (struct ircxmpp *); static void obdelaj_bridge (const void *, VISIT, int); -static void ircxmpp_default_logger ( +static void default_log_handler ( void * const, const enum ircxmpp_loglevel, const char * const, const char * const); // /IRC #endif // IX_LIB -- cgit v1.2.3