Mercurial > hg
comparison mcabber/src/commands.c @ 1073:253e8988eb5c
Fix a few memory leaks after calls to split_arg()
Fix a few memory leaks after calls to split_arg(), esp. in do_msay().
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 03 Dec 2006 19:29:53 +0100 |
parents | 2a3cfb98bd5e |
children | b2fc694a8228 |
comparison
equal
deleted
inserted
replaced
1072:2a3cfb98bd5e | 1073:253e8988eb5c |
---|---|
1007 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); | 1007 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
1008 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " | 1008 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " |
1009 "the /msay command."); | 1009 "the /msay command."); |
1010 scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter " | 1010 scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter " |
1011 "multi-line mode...)", mkcmdstr("msay")); | 1011 "multi-line mode...)", mkcmdstr("msay")); |
1012 free_arg_lst(paramlst); | 1012 goto do_msay_return; |
1013 return; | |
1014 } | 1013 } |
1015 | 1014 |
1016 if (!strcasecmp(subcmd, "toggle")) { | 1015 if (!strcasecmp(subcmd, "toggle")) { |
1017 if (scr_get_multimode()) | 1016 if (scr_get_multimode()) |
1018 subcmd = "send"; | 1017 subcmd = "send"; |
1027 | 1026 |
1028 if (!strcasecmp(subcmd, "abort")) { | 1027 if (!strcasecmp(subcmd, "abort")) { |
1029 if (scr_get_multimode()) | 1028 if (scr_get_multimode()) |
1030 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); | 1029 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); |
1031 scr_set_multimode(FALSE, NULL); | 1030 scr_set_multimode(FALSE, NULL); |
1032 return; | 1031 goto do_msay_return; |
1033 } else if ((!strcasecmp(subcmd, "begin")) || | 1032 } else if ((!strcasecmp(subcmd, "begin")) || |
1034 (!strcasecmp(subcmd, "verbatim"))) { | 1033 (!strcasecmp(subcmd, "verbatim"))) { |
1035 bool verbat; | 1034 bool verbat; |
1036 gchar *subj_utf8 = to_utf8(arg); | 1035 gchar *subj_utf8 = to_utf8(arg); |
1037 if (!strcasecmp(subcmd, "verbatim")) { | 1036 if (!strcasecmp(subcmd, "verbatim")) { |
1048 "when your message is ready.", mkcmdstr("msay")); | 1047 "when your message is ready.", mkcmdstr("msay")); |
1049 if (verbat) | 1048 if (verbat) |
1050 scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.", | 1049 scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.", |
1051 mkcmdstr("msay")); | 1050 mkcmdstr("msay")); |
1052 g_free(subj_utf8); | 1051 g_free(subj_utf8); |
1053 return; | 1052 goto do_msay_return; |
1054 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { | 1053 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { |
1055 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); | 1054 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
1056 return; | 1055 goto do_msay_return; |
1057 } | 1056 } |
1058 | 1057 |
1059 /* send/send_to command */ | 1058 /* send/send_to command */ |
1060 | 1059 |
1061 if (!scr_get_multimode()) { | 1060 if (!scr_get_multimode()) { |
1062 scr_LogPrint(LPRINT_NORMAL, "No message to send. " | 1061 scr_LogPrint(LPRINT_NORMAL, "No message to send. " |
1063 "Use \"%s begin\" first.", mkcmdstr("msay")); | 1062 "Use \"%s begin\" first.", mkcmdstr("msay")); |
1064 return; | 1063 goto do_msay_return; |
1065 } | 1064 } |
1066 | 1065 |
1067 scr_set_chatmode(TRUE); | 1066 scr_set_chatmode(TRUE); |
1068 | 1067 |
1069 if (!strcasecmp(subcmd, "send_to")) { | 1068 if (!strcasecmp(subcmd, "send_to")) { |
1077 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj()); | 1076 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj()); |
1078 g_free(msg_utf8); | 1077 g_free(msg_utf8); |
1079 } | 1078 } |
1080 g_free(arg); | 1079 g_free(arg); |
1081 if (err) | 1080 if (err) |
1082 return; | 1081 goto do_msay_return; |
1083 } else { // Send to currently selected buddy | 1082 } else { // Send to currently selected buddy |
1084 gpointer bud; | 1083 gpointer bud; |
1085 gchar *msg_utf8; | 1084 gchar *msg_utf8; |
1086 | 1085 |
1087 if (!current_buddy) { | 1086 if (!current_buddy) { |
1088 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?"); | 1087 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?"); |
1089 return; | 1088 goto do_msay_return; |
1090 } | 1089 } |
1091 | 1090 |
1092 bud = BUDDATA(current_buddy); | 1091 bud = BUDDATA(current_buddy); |
1093 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { | 1092 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { |
1094 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); | 1093 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); |
1095 return; | 1094 goto do_msay_return; |
1096 } | 1095 } |
1097 | 1096 |
1098 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | 1097 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
1099 msg_utf8 = to_utf8(scr_get_multiline()); | 1098 msg_utf8 = to_utf8(scr_get_multiline()); |
1100 if (msg_utf8) { | 1099 if (msg_utf8) { |
1102 g_free(msg_utf8); | 1101 g_free(msg_utf8); |
1103 } | 1102 } |
1104 } | 1103 } |
1105 scr_set_multimode(FALSE, NULL); | 1104 scr_set_multimode(FALSE, NULL); |
1106 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode."); | 1105 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode."); |
1106 do_msay_return: | |
1107 free_arg_lst(paramlst); | |
1107 } | 1108 } |
1108 | 1109 |
1109 static void do_say_to(char *arg) | 1110 static void do_say_to(char *arg) |
1110 { | 1111 { |
1111 char **paramlst; | 1112 char **paramlst; |
2246 } | 2247 } |
2247 | 2248 |
2248 if (current_buddy) { | 2249 if (current_buddy) { |
2249 bud = BUDDATA(current_buddy); | 2250 bud = BUDDATA(current_buddy); |
2250 } else { | 2251 } else { |
2251 if (strcasecmp(subcmd, "join")) | 2252 if (strcasecmp(subcmd, "join")) { |
2253 free_arg_lst(paramlst); | |
2252 return; | 2254 return; |
2255 } | |
2253 // "room join" is a special case, we don't need to have a valid | 2256 // "room join" is a special case, we don't need to have a valid |
2254 // current_buddy. | 2257 // current_buddy. |
2255 bud = NULL; | 2258 bud = NULL; |
2256 } | 2259 } |
2257 | 2260 |
2325 subcmd = *paramlst; | 2328 subcmd = *paramlst; |
2326 arg = *(paramlst+1); | 2329 arg = *(paramlst+1); |
2327 | 2330 |
2328 if (!subcmd || !*subcmd) { | 2331 if (!subcmd || !*subcmd) { |
2329 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); | 2332 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
2330 free_arg_lst(paramlst); | 2333 goto do_authorization_return; |
2331 return; | |
2332 } | 2334 } |
2333 | 2335 |
2334 // Use the provided jid, if it looks valid | 2336 // Use the provided jid, if it looks valid |
2335 if (arg) { | 2337 if (arg) { |
2336 if (!*arg) { | 2338 if (!*arg) { |
2338 arg = NULL; | 2340 arg = NULL; |
2339 } else { | 2341 } else { |
2340 if (check_jid_syntax(arg)) { | 2342 if (check_jid_syntax(arg)) { |
2341 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, | 2343 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
2342 "<%s> is not a valid Jabber ID.", arg); | 2344 "<%s> is not a valid Jabber ID.", arg); |
2343 free_arg_lst(paramlst); | 2345 goto do_authorization_return; |
2344 return; | |
2345 } | 2346 } |
2346 } | 2347 } |
2347 } | 2348 } |
2348 | 2349 |
2349 if (!arg) { // Use the current selected buddy's jid | 2350 if (!arg) { // Use the current selected buddy's jid |
2350 gpointer bud; | 2351 gpointer bud; |
2351 guint type; | 2352 guint type; |
2352 | 2353 |
2353 if (!current_buddy) | 2354 if (!current_buddy) |
2354 return; | 2355 goto do_authorization_return; |
2355 bud = BUDDATA(current_buddy); | 2356 bud = BUDDATA(current_buddy); |
2356 | 2357 |
2357 jid_utf8 = arg = (char*)buddy_getjid(bud); | 2358 jid_utf8 = arg = (char*)buddy_getjid(bud); |
2358 type = buddy_gettype(bud); | 2359 type = buddy_gettype(bud); |
2359 | 2360 |
2360 if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) { | 2361 if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) { |
2361 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy."); | 2362 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy."); |
2362 return; | 2363 goto do_authorization_return; |
2363 } | 2364 } |
2364 } else { | 2365 } else { |
2365 jid_utf8 = to_utf8(arg); | 2366 jid_utf8 = to_utf8(arg); |
2366 } | 2367 } |
2367 | 2368 |
2389 } | 2390 } |
2390 | 2391 |
2391 // Only free jid_utf8 if it has been allocated, i.e. if != arg. | 2392 // Only free jid_utf8 if it has been allocated, i.e. if != arg. |
2392 if (jid_utf8 && jid_utf8 != arg) | 2393 if (jid_utf8 && jid_utf8 != arg) |
2393 g_free(jid_utf8); | 2394 g_free(jid_utf8); |
2395 do_authorization_return: | |
2394 free_arg_lst(paramlst); | 2396 free_arg_lst(paramlst); |
2395 } | 2397 } |
2396 | 2398 |
2397 static void do_version(char *arg) | 2399 static void do_version(char *arg) |
2398 { | 2400 { |