]> granicus.if.org Git - neomutt/commitdiff
unify new/free() functions 3
authorRichard Russon <rich@flatcap.org>
Sat, 31 Aug 2019 14:19:12 +0000 (15:19 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 1 Sep 2019 16:37:03 +0000 (17:37 +0100)
'Free' functions:
- Name ends in `_free()`
- Take a `**ptr`
- Creates a native pointer
- Sets pointer to `NULL`

Functions changed:
- compress_info_free()
- crypt_key_free()
- key_free()
- lookup_free()
- maildir_entry_free()
- maildir_free()
- menu_free()
- mhs_sequences_free()
- mix_type2_list_free()
- mutt_actx_entries_free()
- mutt_attachmatch_free()
- mutt_colors_free()
- mutt_color_free()
- mutt_color_list_free()
- mutt_keys_free()
- mutt_opts_free()
- myvar_free()
- parameter_free()
- pgp_key_free()
- pgp_uid_free()
- recipient_set_free()
- smime_key_free()

'New' functions:
- Name ends in `_new()`
- Must be a 'new' function if there's a 'free' function

Functions changed:
- lookup_new()
- maildir_entry_new()
- myvar_new()

30 files changed:
autocrypt/autocrypt_acct_menu.c
color.c
color.h
compose.c
compress.c
email/attach.c
email/attach.h
email/rfc2231.c
init.c
keymap.c
keymap.h
maildir/maildir_private.h
maildir/mh.c
maildir/shared.c
main.c
mutt.h
mutt/charset.c
myvar.c
ncrypt/crypt_gpgme.c
ncrypt/pgp.c
ncrypt/pgpkey.c
ncrypt/pgplib.c
ncrypt/pgplib.h
ncrypt/smime.c
pager.c
recvattach.c
remailer.c
test/Makefile.autosetup
test/attach/mutt_actx_entries_free.c [moved from test/attach/mutt_actx_free_entries.c with 79% similarity]
test/main.c

index 8b9ed437119545b7da9cd67f7cb4135cb6493156..cb3ba2655df82ab8147cd35b7527a2229fc36031 100644 (file)
@@ -194,7 +194,7 @@ static struct Menu *create_menu(void)
     entries[i].num = i + 1;
     /* note: we are transfering the account pointer to the entries
      * array, and freeing the accounts array below.  the account
-     * will be freed in free_menu().  */
+     * will be freed in menu_free().  */
     entries[i].account = accounts[i];
 
     entries[i].addr = mutt_addr_new();
@@ -209,10 +209,10 @@ static struct Menu *create_menu(void)
 }
 
 /**
- * free_menu - Free the Autocrypt account Menu
+ * menu_free - Free the Autocrypt account Menu
  * @param menu Menu to free
  */
-static void free_menu(struct Menu **menu)
+static void menu_free(struct Menu **menu)
 {
   struct AccountEntry *entries = (struct AccountEntry *) (*menu)->data;
 
@@ -287,7 +287,7 @@ void mutt_autocrypt_account_menu(void)
       case OP_AUTOCRYPT_CREATE_ACCT:
         if (!mutt_autocrypt_account_init(false))
         {
-          free_menu(&menu);
+          menu_free(&menu);
           menu = create_menu();
         }
         break;
@@ -305,7 +305,7 @@ void mutt_autocrypt_account_menu(void)
 
           if (!mutt_autocrypt_db_account_delete(entry->account))
           {
-            free_menu(&menu);
+            menu_free(&menu);
             menu = create_menu();
           }
         }
@@ -331,5 +331,5 @@ void mutt_autocrypt_account_menu(void)
     }
   }
 
-  free_menu(&menu);
+  menu_free(&menu);
 }
diff --git a/color.c b/color.c
index 57d4d54d98661f6439a0210e083d6002036dbbbb..b54178c9619825926b1c7fff22d20bc9656b12c3 100644 (file)
--- a/color.c
+++ b/color.c
@@ -196,7 +196,7 @@ static void color_line_free(struct ColorLine **ptr, bool free_colors)
 
 #ifdef HAVE_COLOR
   if (free_colors && (cl->fg != COLOR_UNSET) && (cl->bg != COLOR_UNSET))
-    mutt_free_color(cl->fg, cl->bg);
+    mutt_color_free(cl->fg, cl->bg);
 #endif
 
   regfree(&cl->regex);
@@ -409,13 +409,13 @@ int mutt_combine_color(uint32_t fg_attr, uint32_t bg_attr)
 }
 
 /**
- * mutt_free_color - Free a colour
+ * mutt_color_free - Free a colour
  * @param fg Foreground colour ID
  * @param bg Background colour ID
  *
  * If there are no more users, the resource will be freed.
  */
-void mutt_free_color(uint32_t fg, uint32_t bg)
+void mutt_color_free(uint32_t fg, uint32_t bg)
 {
   struct ColorList *q = NULL;
 
@@ -788,7 +788,7 @@ static enum CommandResult add_pattern(struct ColorLineList *top, const char *s,
     {
       if ((tmp->fg != fg) || (tmp->bg != bg))
       {
-        mutt_free_color(tmp->fg, tmp->bg);
+        mutt_color_free(tmp->fg, tmp->bg);
         tmp->fg = fg;
         tmp->bg = bg;
         attr |= mutt_alloc_color(fg, bg);
@@ -1244,10 +1244,10 @@ enum CommandResult mutt_parse_mono(struct Buffer *buf, struct Buffer *s,
 }
 
 /**
- * mutt_free_color_list - Free a list of colours
+ * mutt_color_list_free - Free a list of colours
  * @param list ColorLine List
  */
-static void mutt_free_color_list(struct ColorLineList *list)
+static void mutt_color_list_free(struct ColorLineList *list)
 {
   struct ColorLine *np = NULL, *tmp = NULL;
   STAILQ_FOREACH_SAFE(np, list, entries, tmp)
@@ -1258,19 +1258,19 @@ static void mutt_free_color_list(struct ColorLineList *list)
 }
 
 /**
- * mutt_free_colors - Free all the colours (on shutdown)
+ * mutt_colors_free - Free all the colours (on shutdown)
  */
-void mutt_free_colors(void)
+void mutt_colors_free(void)
 {
-  mutt_free_color_list(&ColorAttachList);
-  mutt_free_color_list(&ColorBodyList);
-  mutt_free_color_list(&ColorHdrList);
-  mutt_free_color_list(&ColorIndexAuthorList);
-  mutt_free_color_list(&ColorIndexFlagsList);
-  mutt_free_color_list(&ColorIndexList);
-  mutt_free_color_list(&ColorIndexSubjectList);
-  mutt_free_color_list(&ColorIndexTagList);
-  mutt_free_color_list(&ColorStatusList);
+  mutt_color_list_free(&ColorAttachList);
+  mutt_color_list_free(&ColorBodyList);
+  mutt_color_list_free(&ColorHdrList);
+  mutt_color_list_free(&ColorIndexAuthorList);
+  mutt_color_list_free(&ColorIndexFlagsList);
+  mutt_color_list_free(&ColorIndexList);
+  mutt_color_list_free(&ColorIndexSubjectList);
+  mutt_color_list_free(&ColorIndexTagList);
+  mutt_color_list_free(&ColorStatusList);
 
   struct ColorList *cl = ColorList;
   struct ColorList *next = NULL;
diff --git a/color.h b/color.h
index 12a66a9267193a07310da18aea8a5685a74bc706..85c08b293f17f0806f142ee0e6a50cf6a7c87975 100644 (file)
--- a/color.h
+++ b/color.h
@@ -31,8 +31,8 @@ struct Buffer;
 void ci_start_color(void);
 int  mutt_alloc_color(uint32_t fg, uint32_t bg);
 int  mutt_combine_color(uint32_t fg_attr, uint32_t bg_attr);
-void mutt_free_color(uint32_t fg, uint32_t bg);
-void mutt_free_colors(void);
+void mutt_color_free(uint32_t fg, uint32_t bg);
+void mutt_colors_free(void);
 enum CommandResult mutt_parse_color(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 enum CommandResult mutt_parse_mono(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 enum CommandResult mutt_parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
index c8b15dcdebc62ac8da1ae20d904d89129af7cabe..71adf89fc5d070cc9bb3c9b82992650a239611be 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -1259,7 +1259,7 @@ int mutt_compose_menu(struct Email *e, char *fcc, size_t fcclen, struct Email *e
         /* attachments may have been added */
         if (actx->idxlen && actx->idx[actx->idxlen - 1]->content->next)
         {
-          mutt_actx_free_entries(actx);
+          mutt_actx_entries_free(actx);
           mutt_update_compose_menu(actx, menu, true);
         }
 
index d4566997ab2511704d279bca45a2357563a84651..6a28c2685bebc4866dde80b4bbceaad44f1bb79f 100644 (file)
@@ -230,10 +230,10 @@ static struct CompressInfo *set_compress_info(struct Mailbox *m)
 }
 
 /**
- * free_compress_info - Frees the compress info members and structure
+ * compress_info_free - Frees the compress info members and structure
  * @param m Mailbox to free compress_info for
  */
-static void free_compress_info(struct Mailbox *m)
+static void compress_info_free(struct Mailbox *m)
 {
   if (!m || !m->compress_info)
     return;
@@ -500,7 +500,7 @@ static int comp_mbox_open(struct Mailbox *m)
 cmo_fail:
   /* remove the partial uncompressed file */
   remove(mailbox_path(m));
-  free_compress_info(m);
+  compress_info_free(m);
   return -1;
 }
 
@@ -579,7 +579,7 @@ cmoa_fail2:
   remove(mailbox_path(m));
 cmoa_fail1:
   /* Free the compress_info to prevent close from trying to recompress */
-  free_compress_info(m);
+  compress_info_free(m);
 
   return -1;
 }
@@ -697,7 +697,7 @@ static int comp_mbox_close(struct Mailbox *m)
   const struct MxOps *ops = ci->child_ops;
   if (!ops)
   {
-    free_compress_info(m);
+    compress_info_free(m);
     return -1;
   }
 
@@ -745,7 +745,7 @@ static int comp_mbox_close(struct Mailbox *m)
     }
   }
 
-  free_compress_info(m);
+  compress_info_free(m);
 
   return 0;
 }
index 4c4c8df9f31870969f6a7be6d89425409d531b5a..b4cc1f053cfd30bd5920ec14217d4282925efd04 100644 (file)
@@ -97,10 +97,10 @@ void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body)
 }
 
 /**
- * mutt_actx_free_entries - Free entries in an Attachment Context
+ * mutt_actx_entries_free - Free entries in an Attachment Context
  * @param actx Attachment context
  */
-void mutt_actx_free_entries(struct AttachCtx *actx)
+void mutt_actx_entries_free(struct AttachCtx *actx)
 {
   if (!actx)
     return;
@@ -144,7 +144,7 @@ void mutt_actx_free(struct AttachCtx **ptr)
 
   struct AttachCtx *actx = *ptr;
 
-  mutt_actx_free_entries(actx);
+  mutt_actx_entries_free(actx);
   FREE(&actx->idx);
   FREE(&actx->v2r);
   FREE(&actx->fp_idx);
index 0c38c37db79232ff2c3dba7f186e489b61f43aa5..3316059fd639a5b8dbd939361c8240cd872e23a9 100644 (file)
@@ -71,7 +71,7 @@ void              mutt_actx_add_attach  (struct AttachCtx *actx, struct AttachPt
 void              mutt_actx_add_body    (struct AttachCtx *actx, struct Body *new_body);
 void              mutt_actx_add_fp      (struct AttachCtx *actx, FILE *fp_new);
 void              mutt_actx_free        (struct AttachCtx **ptr);
-void              mutt_actx_free_entries(struct AttachCtx *actx);
+void              mutt_actx_entries_free(struct AttachCtx *actx);
 struct AttachCtx *mutt_actx_new         (void);
 
 #endif /* MUTT_EMAIL_ATTACH_H */
index b571f9b62e9c67661b7f3170e4460affd0033e23..aa6419d3b16948f23027c0e7927af0445561ad77 100644 (file)
@@ -164,10 +164,10 @@ static void list_insert(struct Rfc2231Parameter **list, struct Rfc2231Parameter
 }
 
 /**
- * free_parameter - Free an Rfc2231Parameter
+ * parameter_free - Free an Rfc2231Parameter
  * @param[out] p Rfc2231Parameter to free
  */
-static void free_parameter(struct Rfc2231Parameter **p)
+static void parameter_free(struct Rfc2231Parameter **p)
 {
   if (!p || !*p)
     return;
@@ -213,7 +213,7 @@ static void join_continuations(struct ParameterList *pl, struct Rfc2231Parameter
       l += vl;
 
       struct Rfc2231Parameter *q = par->next;
-      free_parameter(&par);
+      parameter_free(&par);
       par = q;
       if (par)
         valp = par->value;
diff --git a/init.c b/init.c
index 6e15fa76c208d8778f194072cd96212d7e09a2c2..b6f70ee7945f08d4063259543fc5cef12b08d22a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2281,18 +2281,20 @@ static enum CommandResult parse_unalternates(struct Buffer *buf, struct Buffer *
 
 /**
  * mutt_attachmatch_free - Free an AttachMatch - Implements ::list_free_t
+ * @param ptr AttachMatch to free
  *
  * @note We don't free minor because it is either a pointer into major,
  *       or a static string.
  */
-void mutt_attachmatch_free(struct AttachMatch **am)
+void mutt_attachmatch_free(struct AttachMatch **ptr)
 {
-  if (!am || !*am)
+  if (!ptr || !*ptr)
     return;
 
-  regfree(&(*am)->minor_regex);
-  FREE(&(*am)->major);
-  FREE(am);
+  struct AttachMatch *am = *ptr;
+  regfree(&am->minor_regex);
+  FREE(&am->major);
+  FREE(ptr);
 }
 
 /**
@@ -2879,9 +2881,9 @@ int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags
 }
 
 /**
- * mutt_free_opts - clean up before quitting
+ * mutt_opts_free - clean up before quitting
  */
-void mutt_free_opts(void)
+void mutt_opts_free(void)
 {
   mutt_list_free(&MuttrcStack);
 
@@ -2923,7 +2925,7 @@ void mutt_free_opts(void)
   mutt_list_free_type(&InlineAllow, (list_free_t) mutt_attachmatch_free);
   mutt_list_free_type(&InlineExclude, (list_free_t) mutt_attachmatch_free);
 
-  mutt_free_colors();
+  mutt_colors_free();
 
   FREE(&CurrentFolder);
   FREE(&HomeDir);
@@ -2937,7 +2939,7 @@ void mutt_free_opts(void)
   mutt_delete_hooks(MUTT_HOOK_NO_FLAGS);
 
   mutt_hist_free();
-  mutt_free_keys();
+  mutt_keys_free();
 
   mutt_regexlist_free(&NoSpamList);
 }
index 72fcfa5b12ffe3790dfc049c230b3fe88e400136..a0f348614884984b5bd56c3526284c828c08d2a7 100644 (file)
--- a/keymap.c
+++ b/keymap.c
@@ -1592,9 +1592,9 @@ void mutt_what_key(void)
 }
 
 /**
- * mutt_free_keys - Free the key maps
+ * mutt_keys_free - Free the key maps
  */
-void mutt_free_keys(void)
+void mutt_keys_free(void)
 {
   struct Keymap *map = NULL;
   struct Keymap *next = NULL;
index fd59f74d638a5843e5b63782e3a0c245db2b142e..138f9216a07c97f613d6af608dc6e2e503fe9408 100644 (file)
--- a/keymap.h
+++ b/keymap.h
@@ -135,7 +135,7 @@ extern const struct Binding OpMix[];
 extern const struct Binding OpAutocryptAcct[];
 #endif
 
-void mutt_free_keys(void);
+void mutt_keys_free(void);
 
 enum CommandResult mutt_parse_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 enum CommandResult mutt_parse_exec(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
index c00dbc335330e49f53b4eb37147b6a6f0c2e9740..7e41ac94b069c13398a26d0472c11de6328451b3 100644 (file)
@@ -100,7 +100,7 @@ int                     mh_mkstemp             (struct Mailbox *m, FILE **fp, ch
 int                     mh_read_dir            (struct Mailbox *m, const char *subdir);
 int                     mh_read_sequences      (struct MhSequences *mhs, const char *path);
 MhSeqFlags              mhs_check              (struct MhSequences *mhs, int i);
-void                    mhs_free_sequences     (struct MhSequences *mhs);
+void                    mhs_sequences_free     (struct MhSequences *mhs);
 MhSeqFlags              mhs_set                (struct MhSequences *mhs, int i, MhSeqFlags f);
 mode_t                  mh_umask               (struct Mailbox *m);
 void                    mh_update_maildir      (struct Maildir *md, struct MhSequences *mhs);
index d043511702afae11a9f970bae04d86c047d61664..10d4a9b8a7b490700c231f1ce38b30f899833274 100644 (file)
@@ -73,10 +73,10 @@ static void mhs_alloc(struct MhSequences *mhs, int i)
 }
 
 /**
- * mhs_free_sequences - Free some sequences
+ * mhs_sequences_free - Free some sequences
  * @param mhs Sequences to free
  */
-void mhs_free_sequences(struct MhSequences *mhs)
+void mhs_sequences_free(struct MhSequences *mhs)
 {
   FREE(&mhs->flags);
 }
@@ -252,7 +252,7 @@ void mh_update_sequences(struct Mailbox *m)
   if (replied)
     mhs_write_one_sequence(fp_new, &mhs, MH_SEQ_REPLIED, NONULL(C_MhSeqReplied));
 
-  mhs_free_sequences(&mhs);
+  mhs_sequences_free(&mhs);
 
   /* try to commit the changes - no guarantee here */
   mutt_file_fclose(&fp_new);
@@ -335,7 +335,7 @@ int mh_read_sequences(struct MhSequences *mhs, const char *path)
     {
       if (mh_read_token(t, &first, &last) < 0)
       {
-        mhs_free_sequences(mhs);
+        mhs_sequences_free(mhs);
         rc = -1;
         goto out;
       }
@@ -466,7 +466,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags)
     }
   }
 
-  mhs_free_sequences(&mhs);
+  mhs_sequences_free(&mhs);
 
   dirp = opendir(mailbox_path(m));
   if (dirp)
@@ -666,7 +666,7 @@ int mh_mbox_check(struct Mailbox *m, int *index_hint)
   if (mh_read_sequences(&mhs, mailbox_path(m)) < 0)
     return -1;
   mh_update_maildir(md, &mhs);
-  mhs_free_sequences(&mhs);
+  mhs_sequences_free(&mhs);
 
   /* check for modifications and adjust flags */
   fnames = mutt_hash_new(count, MUTT_HASH_NO_FLAGS);
index 2676943c7224a1ed78ca4af0a4b9299cd76efcfb..3f8c27350ee9cfa8833ab06746cf90a82b4522a7 100644 (file)
@@ -254,26 +254,35 @@ static void mh_sequences_add_one(struct Mailbox *m, int n, bool unseen, bool fla
 }
 
 /**
- * maildir_free_entry - Free a Maildir object
- * @param[out] md Maildir to free
+ * maildir_entry_new - Create a new Maildir entry
+ * @retval ptr New Maildir entry
  */
-static void maildir_free_entry(struct Maildir **md)
+static struct Maildir *maildir_entry_new(void)
 {
-  if (!md || !*md)
+  return mutt_mem_calloc(1, sizeof(struct Maildir));
+}
+
+/**
+ * maildir_entry_free - Free a Maildir object
+ * @param[out] ptr Maildir to free
+ */
+static void maildir_entry_free(struct Maildir **ptr)
+{
+  if (!ptr || !*ptr)
     return;
 
-  FREE(&(*md)->canon_fname);
-  if ((*md)->email)
-    email_free(&(*md)->email);
+  struct Maildir *md = *ptr;
+  FREE(&md->canon_fname);
+  email_free(&md->email);
 
-  FREE(md);
+  FREE(ptr);
 }
 
 /**
- * maildir_free_maildir - Free a Maildir list
+ * maildir_free - Free a Maildir list
  * @param[out] md Maildir list to free
  */
-static void maildir_free_maildir(struct Maildir **md)
+static void maildir_free(struct Maildir **md)
 {
   if (!md || !*md)
     return;
@@ -283,7 +292,7 @@ static void maildir_free_maildir(struct Maildir **md)
   for (p = *md; p; p = q)
   {
     q = p->next;
-    maildir_free_entry(&p);
+    maildir_entry_free(&p);
   }
 }
 
@@ -385,7 +394,7 @@ int maildir_parse_dir(struct Mailbox *m, struct Maildir ***last,
     else
       e->path = mutt_str_strdup(de->d_name);
 
-    entry = mutt_mem_calloc(1, sizeof(struct Maildir));
+    entry = maildir_entry_new();
     entry->email = e;
     entry->inode = de->d_ino;
     **last = entry;
@@ -455,7 +464,7 @@ int maildir_move_to_mailbox(struct Mailbox *m, struct Maildir **ptr)
   if (m->msg_count > oldmsgcount)
     num = m->msg_count - oldmsgcount;
 
-  maildir_free_maildir(ptr);
+  maildir_free(ptr);
   return num;
 }
 
@@ -839,11 +848,11 @@ int mh_read_dir(struct Mailbox *m, const char *subdir)
   {
     if (mh_read_sequences(&mhs, mailbox_path(m)) < 0)
     {
-      maildir_free_maildir(&md);
+      maildir_free(&md);
       return -1;
     }
     mh_update_maildir(md, &mhs);
-    mhs_free_sequences(&mhs);
+    mhs_sequences_free(&mhs);
   }
 
   maildir_move_to_mailbox(m, &md);
diff --git a/main.c b/main.c
index 2ab5a483510c62b89612d434ae73620290f82128..22a58044bbb0434e3053c2225d32d553d69b09d9 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1277,8 +1277,8 @@ main_exit:
   mutt_buffer_pool_free();
   mutt_envlist_free();
   mutt_browser_cleanup();
-  mutt_free_opts();
-  mutt_free_keys();
+  mutt_opts_free();
+  mutt_keys_free();
   neomutt_free(&NeoMutt);
   cs_free(&Config);
   return rc;
diff --git a/mutt.h b/mutt.h
index 63431d0db4c4e1234beb6847c7286daff781a1f5..b765775a5e4d7d7ea8f992014d36271dd3f3ed50 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -141,7 +141,7 @@ struct AttachMatch
 char *mutt_compile_help(char *buf, size_t buflen, enum MenuType menu, const struct Mapping *items);
 
 int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags);
-void mutt_free_opts(void);
+void mutt_opts_free(void);
 enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt);
 int mutt_label_complete(char *buf, size_t buflen, int numtabs);
 int mutt_command_complete(char *buf, size_t buflen, int pos, int numtabs);
index f6e89385eb0a0499d64e723318245ccbc6245da4..900aea32014d03fac4a1845a230c3f5027bd17d9 100644 (file)
@@ -79,6 +79,35 @@ TAILQ_HEAD(LookupList, Lookup);
 
 static struct LookupList Lookups = TAILQ_HEAD_INITIALIZER(Lookups);
 
+/**
+ * lookup_new - Create a new Lookup
+ * @retval ptr New Lookup
+ */
+struct Lookup *lookup_new(void)
+{
+  return mutt_mem_calloc(1, sizeof(struct Lookup));
+}
+
+/**
+ * lookup_free - Free a Lookup
+ * @param ptr Lookup to free
+ */
+void lookup_free(struct Lookup **ptr)
+{
+  if (!ptr || !*ptr)
+    return;
+
+  struct Lookup *l = *ptr;
+  FREE(&l->replacement);
+  FREE(&l->regex.pattern);
+  if (l->regex.regex)
+    regfree(l->regex.regex);
+  FREE(&l->regex.regex);
+  FREE(&l->regex);
+
+  FREE(ptr);
+}
+
 // clang-format off
 /**
  * PreferredMimeNames - Lookup table of preferred charsets
@@ -462,7 +491,7 @@ bool mutt_ch_lookup_add(enum LookupType type, const char *pat,
     return false;
   }
 
-  struct Lookup *l = mutt_mem_calloc(1, sizeof(struct Lookup));
+  struct Lookup *l = lookup_new();
   l->type = type;
   l->replacement = mutt_str_strdup(replace);
   l->regex.pattern = mutt_str_strdup(pat);
@@ -487,13 +516,7 @@ void mutt_ch_lookup_remove(void)
   TAILQ_FOREACH_SAFE(l, &Lookups, entries, tmp)
   {
     TAILQ_REMOVE(&Lookups, l, entries);
-    FREE(&l->replacement);
-    FREE(&l->regex.pattern);
-    if (l->regex.regex)
-      regfree(l->regex.regex);
-    FREE(&l->regex.regex);
-    FREE(&l->regex);
-    FREE(&l);
+    lookup_free(&l);
   }
 }
 
diff --git a/myvar.c b/myvar.c
index d38ba5a8df559df2c7b3218ebd0221172dadbc02..b2c1957f3b3f01deabb7ac6070413bf0baf6b8d3 100644 (file)
--- a/myvar.c
+++ b/myvar.c
 
 struct MyVarList MyVars = TAILQ_HEAD_INITIALIZER(MyVars);
 
+/**
+ * myvar_new - Create a new MyVar
+ * @param name  Variable name
+ * @param value Variable value
+ * @retval ptr New MyVar
+ *
+ * @note The name and value will be copied.
+ */
+static struct MyVar *myvar_new(const char *name, const char *value)
+{
+  struct MyVar *myv = mutt_mem_calloc(1, sizeof(struct MyVar));
+  myv->name = mutt_str_strdup(name);
+  myv->value = mutt_str_strdup(value);
+  return myv;
+}
+
+/**
+ * myvar_free - Free a MyVar
+ * @param ptr MyVar to free
+ */
+void myvar_free(struct MyVar **ptr)
+{
+  if (!ptr || !*ptr)
+    return;
+
+  struct MyVar *myv = *ptr;
+  FREE(&myv->name);
+  FREE(&myv->value);
+  FREE(ptr);
+}
+
 /**
  * myvar_get - Get the value of a "my_" variable
  * @param var Variable name
@@ -70,9 +101,7 @@ void myvar_set(const char *var, const char *val)
     }
   }
 
-  myv = mutt_mem_calloc(1, sizeof(struct MyVar));
-  myv->name = mutt_str_strdup(var);
-  myv->value = mutt_str_strdup(val);
+  myv = myvar_new(var, val);
   TAILQ_INSERT_TAIL(&MyVars, myv, entries);
 }
 
@@ -89,9 +118,7 @@ void myvar_del(const char *var)
     if (mutt_str_strcmp(myv->name, var) == 0)
     {
       TAILQ_REMOVE(&MyVars, myv, entries);
-      FREE(&myv->name);
-      FREE(&myv->value);
-      FREE(&myv);
+      myvar_free(&myv);
       return;
     }
   }
index 97e3b4405af67db11968cb9a91f211661d7e0048..4bf238bfa91079fee72cf9f0c99271dd88285ac3 100644 (file)
@@ -633,10 +633,10 @@ static struct CryptKeyInfo *crypt_copy_key(struct CryptKeyInfo *key)
 }
 
 /**
- * crypt_free_key - Release all the keys in a list
+ * crypt_key_free - Release all the keys in a list
  * @param[out] keylist List of keys
  */
-static void crypt_free_key(struct CryptKeyInfo **keylist)
+static void crypt_key_free(struct CryptKeyInfo **keylist)
 {
   if (!keylist)
     return;
@@ -1067,10 +1067,10 @@ static void create_recipient_string(const char *keylist, struct Buffer *recpstri
 
 #else
 /**
- * free_recipient_set - Free a set of recipients
+ * recipient_set_free - Free a set of recipients
  * @param p_rset Set of GPGME keys
  */
-static void free_recipient_set(gpgme_key_t **p_rset)
+static void recipient_set_free(gpgme_key_t **p_rset)
 {
   gpgme_key_t *rset = NULL;
 
@@ -1138,7 +1138,7 @@ static gpgme_key_t *create_recipient_set(const char *keylist, bool use_smime)
       {
         mutt_error(_("error adding recipient '%s': %s"), buf, gpgme_strerror(err));
         rset[rset_n] = NULL;
-        free_recipient_set(&rset);
+        recipient_set_free(&rset);
         gpgme_release(context);
         return NULL;
       }
@@ -1324,7 +1324,7 @@ cleanup:
 #if (GPGME_VERSION_NUMBER >= 0x010b00) /* gpgme >= 1.11.0 */
   mutt_buffer_pool_release(&recpstring);
 #else
-  free_recipient_set(&rset);
+  recipient_set_free(&rset);
 #endif
   gpgme_release(ctx);
   gpgme_data_release(ciphertext);
@@ -4984,7 +4984,7 @@ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a,
     }
   }
 
-  crypt_free_key(&keys);
+  crypt_key_free(&keys);
 
   if (matches)
   {
@@ -5009,7 +5009,7 @@ static struct CryptKeyInfo *crypt_getkeybyaddr(struct Address *a,
       k = crypt_select_key(matches, a, NULL, app, forced_valid);
     }
 
-    crypt_free_key(&matches);
+    crypt_key_free(&matches);
   }
   else
     k = NULL;
@@ -5075,12 +5075,12 @@ static struct CryptKeyInfo *crypt_getkeybystr(const char *p, KeyFlags abilities,
   }
 
   FREE(&pfcopy);
-  crypt_free_key(&keys);
+  crypt_key_free(&keys);
 
   if (matches)
   {
     k = crypt_select_key(matches, NULL, p, app, forced_valid);
-    crypt_free_key(&matches);
+    crypt_key_free(&matches);
     return k;
   }
 
@@ -5272,7 +5272,7 @@ static char *find_keys(struct AddressList *addrlist, unsigned int app, bool oppe
 
       key_selected = true;
 
-      crypt_free_key(&k_info);
+      crypt_key_free(&k_info);
       mutt_addrlist_clear(&hookal);
 
       if (crypt_hook)
@@ -5386,8 +5386,8 @@ int mutt_gpgme_select_secret_key(struct Buffer *keyid)
   rc = 0;
 
 cleanup:
-  crypt_free_key(&choice);
-  crypt_free_key(&results);
+  crypt_key_free(&choice);
+  crypt_key_free(&results);
   gpgme_release(ctx);
   return rc;
 }
@@ -5446,7 +5446,7 @@ struct Body *pgp_gpgme_make_key_attachment(void)
   att->length = sb.st_size;
 
 bail:
-  crypt_free_key(&key);
+  crypt_key_free(&key);
   gpgme_data_release(keydata);
   gpgme_release(context);
 
@@ -5614,7 +5614,7 @@ static int gpgme_send_menu(struct Email *e, int is_smime)
           char input_signas[128];
           snprintf(input_signas, sizeof(input_signas), "0x%s", crypt_fpr_or_lkeyid(p));
           mutt_str_replace(is_smime ? &C_SmimeDefaultKey : &C_PgpSignAs, input_signas);
-          crypt_free_key(&p);
+          crypt_key_free(&p);
 
           e->security |= SEC_SIGN;
         }
index 0019d21ecadf84b598f9fb5e241c7c1dc3b00fdd..265cb2c83bb7a4d061886951a51c124120dec5a0 100644 (file)
@@ -1511,7 +1511,7 @@ char *pgp_class_find_keys(struct AddressList *addrlist, bool oppenc_mode)
 
       key_selected = true;
 
-      pgp_free_key(&k_info);
+      pgp_key_free(&k_info);
       mutt_addrlist_clear(&hookal);
 
       if (crypt_hook)
@@ -1963,7 +1963,7 @@ int pgp_class_send_menu(struct Email *e)
           char input_signas[128];
           snprintf(input_signas, sizeof(input_signas), "0x%s", pgp_fpr_or_lkeyid(p));
           mutt_str_replace(&C_PgpSignAs, input_signas);
-          pgp_free_key(&p);
+          pgp_key_free(&p);
 
           e->security |= SEC_SIGN;
 
index 7cd6b74f7b4a73dea9d08481ec9c1bf6f391404f..e9518821aa2b9584ddd0f53e745f3b515a8d8b7b 100644 (file)
@@ -886,7 +886,7 @@ struct Body *pgp_class_make_key_attachment(void)
     return NULL;
 
   snprintf(tmp, sizeof(tmp), "0x%s", pgp_fpr_or_lkeyid(pgp_principal_key(key)));
-  pgp_free_key(&key);
+  pgp_key_free(&key);
 
   mutt_mktemp(tempf, sizeof(tempf));
 
@@ -1070,7 +1070,7 @@ struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities,
     }
   }
 
-  pgp_free_key(&keys);
+  pgp_key_free(&keys);
 
   if (matches)
   {
@@ -1104,7 +1104,7 @@ struct PgpKeyInfo *pgp_getkeybyaddr(struct Address *a, KeyFlags abilities,
         pgp_remove_key(&matches, k);
     }
 
-    pgp_free_key(&matches);
+    pgp_key_free(&matches);
 
     return k;
   }
@@ -1187,14 +1187,14 @@ struct PgpKeyInfo *pgp_getkeybystr(const char *cp, KeyFlags abilities, enum PgpR
     }
   }
 
-  pgp_free_key(&keys);
+  pgp_key_free(&keys);
 
   if (matches)
   {
     k = pgp_select_key(matches, NULL, p);
     if (k)
       pgp_remove_key(&matches, k);
-    pgp_free_key(&matches);
+    pgp_key_free(&matches);
   }
   else
   {
index 1049d5654e4b27b487060bb9718ec9fac929ca92..a90f5b96c8f57dca61b8e4a7de3021a7a829c5eb 100644 (file)
@@ -112,10 +112,10 @@ short pgp_get_abilities(unsigned char type)
 }
 
 /**
- * pgp_free_uid - Free a PGP UID
+ * pgp_uid_free - Free a PGP UID
  * @param[out] upp PGP UID to free
  */
-static void pgp_free_uid(struct PgpUid **upp)
+static void pgp_uid_free(struct PgpUid **upp)
 {
   struct PgpUid *up = NULL, *q = NULL;
 
@@ -156,17 +156,17 @@ struct PgpUid *pgp_copy_uids(struct PgpUid *up, struct PgpKeyInfo *parent)
 }
 
 /**
- * free_key - Free a PGP Key info
+ * key_free - Free a PGP Key info
  * @param[out] kpp PGP Key info to free
  */
-static void free_key(struct PgpKeyInfo **kpp)
+static void key_free(struct PgpKeyInfo **kpp)
 {
   if (!kpp || !*kpp)
     return;
 
   struct PgpKeyInfo *kp = *kpp;
 
-  pgp_free_uid(&kp->address);
+  pgp_uid_free(&kp->address);
   FREE(&kp->keyid);
   FREE(&kp->fingerprint);
   FREE(kpp);
@@ -207,10 +207,10 @@ struct PgpKeyInfo *pgp_remove_key(struct PgpKeyInfo **klist, struct PgpKeyInfo *
 }
 
 /**
- * pgp_free_key - Free a PGP key info
+ * pgp_key_free - Free a PGP key info
  * @param[out] kpp PGP key info to free
  */
-void pgp_free_key(struct PgpKeyInfo **kpp)
+void pgp_key_free(struct PgpKeyInfo **kpp)
 {
   if (!kpp || !*kpp)
     return;
@@ -232,11 +232,11 @@ void pgp_free_key(struct PgpKeyInfo **kpp)
     for (q = p->next; q && q->parent == p; q = r)
     {
       r = q->next;
-      free_key(&q);
+      key_free(&q);
     }
 
-    free_key(&p->parent);
-    free_key(&p);
+    key_free(&p->parent);
+    key_free(&p);
   }
 
   *kpp = NULL;
index b55d7108f582116d853c8162e4c3525314150b68..d575e77ad0c19bd69a5d519473560728ad89d0aa 100644 (file)
@@ -65,7 +65,7 @@ bool pgp_canencrypt(unsigned char type);
 bool pgp_cansign(unsigned char type);
 short pgp_get_abilities(unsigned char type);
 
-void pgp_free_key(struct PgpKeyInfo **kpp);
+void pgp_key_free(struct PgpKeyInfo **kpp);
 
 struct PgpKeyInfo *pgp_remove_key(struct PgpKeyInfo **klist, struct PgpKeyInfo *key);
 
index 596dcdaabbfe67e07fac91b694f13c322bc4528d..882c19bd7e9ff4e9731759c264445ebfb054f9c5 100644 (file)
@@ -107,10 +107,10 @@ static char SmimeCertToUse[PATH_MAX];
 static char fp_smime_intermediateToUse[PATH_MAX];
 
 /**
- * smime_free_key - Free a list of SMIME keys
+ * smime_key_free - Free a list of SMIME keys
  * @param[out] keylist List of keys to free
  */
-static void smime_free_key(struct SmimeKey **keylist)
+static void smime_key_free(struct SmimeKey **keylist)
 {
   if (!keylist)
     return;
@@ -684,7 +684,7 @@ static struct SmimeKey *smime_parse_key(char *buf)
    * but anything less than that is an error. */
   if (field < 3)
   {
-    smime_free_key(&key);
+    smime_key_free(&key);
     return NULL;
   }
 
@@ -763,7 +763,7 @@ static struct SmimeKey *smime_get_key_by_hash(char *hash, bool only_public_key)
     }
   }
 
-  smime_free_key(&results);
+  smime_key_free(&results);
 
   return match;
 }
@@ -820,7 +820,7 @@ static struct SmimeKey *smime_get_key_by_addr(char *mailbox, KeyFlags abilities,
     }
   }
 
-  smime_free_key(&results);
+  smime_key_free(&results);
 
   if (matches)
   {
@@ -842,7 +842,7 @@ static struct SmimeKey *smime_get_key_by_addr(char *mailbox, KeyFlags abilities,
       return_key = smime_copy_key(smime_select_key(matches, mailbox));
     }
 
-    smime_free_key(&matches);
+    smime_key_free(&matches);
   }
 
   return return_key;
@@ -883,12 +883,12 @@ static struct SmimeKey *smime_get_key_by_str(char *str, KeyFlags abilities, bool
     }
   }
 
-  smime_free_key(&results);
+  smime_key_free(&results);
 
   if (matches)
   {
     return_key = smime_copy_key(smime_select_key(matches, str));
-    smime_free_key(&matches);
+    smime_key_free(&matches);
   }
 
   return return_key;
@@ -953,7 +953,7 @@ static void getkeys(char *mailbox)
     if (*SmimeKeyToUse &&
         (mutt_str_strcasecmp(k, SmimeKeyToUse + mutt_str_strlen(C_SmimeKeys) + 1) == 0))
     {
-      smime_free_key(&key);
+      smime_key_free(&key);
       return;
     }
     else
@@ -967,7 +967,7 @@ static void getkeys(char *mailbox)
     if (mutt_str_strcasecmp(k, C_SmimeDefaultKey) != 0)
       smime_class_void_passphrase();
 
-    smime_free_key(&key);
+    smime_key_free(&key);
     return;
   }
 
@@ -1063,7 +1063,7 @@ char *smime_class_find_keys(struct AddressList *al, bool oppenc_mode)
     sprintf(keylist + keylist_used, "%s%s", keylist_used ? " " : "", keyid);
     keylist_used = mutt_str_strlen(keylist);
 
-    smime_free_key(&key);
+    smime_key_free(&key);
   }
   return keylist;
 }
@@ -1742,7 +1742,7 @@ struct Body *smime_class_sign_message(struct Body *a)
   snprintf(fp_smime_intermediateToUse, sizeof(fp_smime_intermediateToUse),
            "%s/%s", NONULL(C_SmimeCertificates), intermediates);
 
-  smime_free_key(&signas_key);
+  smime_key_free(&signas_key);
 
   pid = smime_invoke_sign(&fp_smime_in, NULL, &fp_smime_err, -1,
                           fileno(fp_smime_out), -1, filetosign);
@@ -2363,7 +2363,7 @@ int smime_class_send_menu(struct Email *e)
         if (key)
         {
           mutt_str_replace(&C_SmimeSignAs, key->hash);
-          smime_free_key(&key);
+          smime_key_free(&key);
 
           e->security |= SEC_SIGN;
 
diff --git a/pager.c b/pager.c
index 53bf717c4215e1c4b2a83174d27944d25a485025..0b6b492cd3d381e10f81356caa7ed1a37f4c829a 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1278,7 +1278,7 @@ static int grok_ansi(unsigned char *buf, int pos, struct AnsiAttr *a)
     {
 #ifdef HAVE_COLOR
       if (a->pair != -1)
-        mutt_free_color(a->fg, a->bg);
+        mutt_color_free(a->fg, a->bg);
 #endif
       a->attr = ANSI_OFF;
       a->pair = -1;
@@ -1309,7 +1309,7 @@ static int grok_ansi(unsigned char *buf, int pos, struct AnsiAttr *a)
       {
 #ifdef HAVE_COLOR
         if (a->pair != -1)
-          mutt_free_color(a->fg, a->bg);
+          mutt_color_free(a->fg, a->bg);
 #endif
         a->attr = ANSI_OFF;
         a->pair = -1;
@@ -1319,7 +1319,7 @@ static int grok_ansi(unsigned char *buf, int pos, struct AnsiAttr *a)
       {
 #ifdef HAVE_COLOR
         if (a->pair != -1)
-          mutt_free_color(a->fg, a->bg);
+          mutt_color_free(a->fg, a->bg);
 #endif
         a->pair = -1;
         a->attr |= ANSI_COLOR;
@@ -1330,7 +1330,7 @@ static int grok_ansi(unsigned char *buf, int pos, struct AnsiAttr *a)
       {
 #ifdef HAVE_COLOR
         if (a->pair != -1)
-          mutt_free_color(a->fg, a->bg);
+          mutt_color_free(a->fg, a->bg);
 #endif
         a->pair = -1;
         a->attr |= ANSI_COLOR;
index 1c4924e9c45cbf1838b23348f936617022d260cc..9650a2c9888df8f6f890df75c8fd6a3c7ef425b0 100644 (file)
@@ -1120,7 +1120,7 @@ static void recvattach_edit_content_type(struct AttachCtx *actx,
   /* Editing the content type can rewrite the body structure. */
   for (int i = 0; i < actx->idxlen; i++)
     actx->idx[i]->content = NULL;
-  mutt_actx_free_entries(actx);
+  mutt_actx_entries_free(actx);
   mutt_update_recvattach_menu(actx, menu, true);
 }
 
index eb4d8f12cd5740b1273b68c36baca7ee82da7fd6..32306010077ecb8db165c505db8663c1a1abc880 100644 (file)
@@ -249,10 +249,10 @@ static struct Remailer **mix_type2_list(size_t *l)
 }
 
 /**
- * mix_free_type2_list - Free a Remailer List
+ * mix_type2_list_free - Free a Remailer List
  * @param[out] ttlp Remailer List to free
  */
-static void mix_free_type2_list(struct Remailer ***ttlp)
+static void mix_type2_list_free(struct Remailer ***ttlp)
 {
   struct Remailer **type2_list = *ttlp;
 
@@ -766,7 +766,7 @@ void mix_make_chain(struct ListHead *chainhead)
     }
   }
 
-  mix_free_type2_list(&type2_list);
+  mix_type2_list_free(&type2_list);
   FREE(&coords);
   FREE(&chain);
 }
index b42af1d8aa02aa2c5072eebc38d1261fd790920f..15eff087ada6da26ae4198ccbe6c4c3f2d172305 100644 (file)
@@ -24,7 +24,7 @@ ADDRESS_OBJS  = test/address/mutt_addr_cat.o \
                  test/address/mutt_addrlist_write.o
 
 ATTACH_OBJS    = test/attach/mutt_actx_add_fp.o \
-                 test/attach/mutt_actx_free_entries.o \
+                 test/attach/mutt_actx_entries_free.o \
                  test/attach/mutt_actx_free.o \
                  test/attach/mutt_actx_add_body.o \
                  test/attach/mutt_actx_add_attach.o
similarity index 79%
rename from test/attach/mutt_actx_free_entries.c
rename to test/attach/mutt_actx_entries_free.c
index 68c372a304fcccf8fb2a4fc1f4d1c5a378b3f55b..23f792cbbccb60d9302084bf9854a4570592f5c3 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * @file
- * Test code for mutt_actx_free_entries()
+ * Test code for mutt_actx_entries_free()
  *
  * @authors
  * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
 #include "address/lib.h"
 #include "email/lib.h"
 
-void test_mutt_actx_free_entries(void)
+void test_mutt_actx_entries_free(void)
 {
-  // void mutt_actx_free_entries(struct AttachCtx *actx);
+  // void mutt_actx_entries_free(struct AttachCtx *actx);
 
   {
-    mutt_actx_free_entries(NULL);
-    TEST_CHECK_(1, "mutt_actx_free_entries(NULL)");
+    mutt_actx_entries_free(NULL);
+    TEST_CHECK_(1, "mutt_actx_entries_free(NULL)");
   }
 }
index eebf2ec89a263937949169f2623d870dee07ec41..ce2d9e54c9872694860a1ae87bb9d2174fc9eaa9 100644 (file)
@@ -55,7 +55,7 @@
   NEOMUTT_TEST_ITEM(test_mutt_actx_add_body)                                   \
   NEOMUTT_TEST_ITEM(test_mutt_actx_add_fp)                                     \
   NEOMUTT_TEST_ITEM(test_mutt_actx_free)                                       \
-  NEOMUTT_TEST_ITEM(test_mutt_actx_free_entries)                               \
+  NEOMUTT_TEST_ITEM(test_mutt_actx_entries_free)                               \
   NEOMUTT_TEST_ITEM(test_mutt_b64_buffer_decode)                               \
   NEOMUTT_TEST_ITEM(test_mutt_b64_buffer_encode)                               \
   NEOMUTT_TEST_ITEM(test_mutt_b64_decode)                                      \