Mercurial > pidgin
diff src/cmds.c @ 14035:8bda65b88e49
[gaim-migrate @ 16638]
A bunch of small changes. Mostly remove "if not null" checks before
calling g_free, g_list_free, g_slist_free and g_strdup. Also use
g_list_foreach() to call g_free to free strings in an array. And
some whitespace changes here and there.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 05 Aug 2006 08:27:39 +0000 |
parents | bdf8081b1bc1 |
children |
line wrap: on
line diff
--- a/src/cmds.c Sat Aug 05 05:42:28 2006 +0000 +++ b/src/cmds.c Sat Aug 05 08:27:39 2006 +0000 @@ -71,9 +71,9 @@ c->args = g_strdup(args); c->priority = p; c->flags = f; - c->prpl_id = prpl_id ? g_strdup(prpl_id) : NULL; + c->prpl_id = g_strdup(prpl_id); c->func = func; - c->help = helpstr ? g_strdup(helpstr) : NULL; + c->help = g_strdup(helpstr); c->data = data; cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func); @@ -85,11 +85,8 @@ { g_free(c->cmd); g_free(c->args); - if (c->prpl_id) - g_free(c->prpl_id); - if (c->help) - g_free(c->help); - + g_free(c->prpl_id); + g_free(c->help); g_free(c); } @@ -109,6 +106,10 @@ } } +/** + * This sets args to a NULL-terminated array of strings. It should + * be freed using g_strfreev(). + */ static gboolean gaim_cmd_parse_args(GaimCmd *cmd, const gchar *s, const gchar *m, gchar ***args) { int i; @@ -142,7 +143,7 @@ (*args)[i] = gaim_markup_slice(m, g_utf8_pointer_to_offset(s, cur), g_utf8_pointer_to_offset(s, end)); cur = end +1; } - break; + break; case 's': (*args)[i] = g_strdup(cur); cur = cur + strlen(cur); @@ -160,15 +161,6 @@ return TRUE; } -static void gaim_cmd_free_args(gchar **args) -{ - int i; - - for (i = 0; args[i]; i++) - g_free(args[i]); - g_free(args); -} - static void gaim_cmd_strip_current_char(gunichar c, char *s, guint len) { int bytes; @@ -260,7 +252,7 @@ /* this checks the allow bad args flag for us */ if (!gaim_cmd_parse_args(c, rest, mrest, &args)) { - gaim_cmd_free_args(args); + g_strfreev(args); args = NULL; continue; } @@ -268,10 +260,9 @@ tried_cmd = TRUE; ret = c->func(conv, cmd, args, &err, c->data); if (ret == GAIM_CMD_RET_CONTINUE) { - if (err) - g_free(err); + g_free(err); err = NULL; - gaim_cmd_free_args(args); + g_strfreev(args); args = NULL; continue; } else { @@ -280,8 +271,7 @@ } - if (args) - gaim_cmd_free_args(args); + g_strfreev(args); g_free(cmd); g_free(mrest);