X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=crypt-gpgme.c;h=0c0bbf70f69ab6f5b2a30619b7c5b7c37ec3125e;hp=ef199cb7947ad3f25f4a49062a9094f70298965c;hb=b3cb6ed8d36c550a2e589910ce51bbc8352ff57c;hpb=ef7b80006ebb47372d69c64e8b2b2f0764333d55 diff --git a/crypt-gpgme.c b/crypt-gpgme.c index ef199cb..0c0bbf7 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -18,6 +18,8 @@ #ifdef CRYPT_BACKEND_GPGME +#include + #include "mutt.h" #include "mutt_crypt.h" #include "mutt_menu.h" @@ -132,12 +134,10 @@ static void print_utf8 (FILE * fp, const char *buf, size_t len) { char *tstr; - tstr = mem_malloc (len + 1); - memcpy (tstr, buf, len); - tstr[len] = 0; + tstr = p_dupstr(buf, len); mutt_convert_string (&tstr, "utf-8", Charset, M_ICONV_HOOK_FROM); fputs (tstr, fp); - mem_free (&tstr); + p_delete(&tstr); } @@ -212,11 +212,11 @@ static char crypt_flags (int flags) } /* Return a copy of KEY. */ -static crypt_key_t *crypt_copy_key (crypt_key_t * key) +static crypt_key_t *crypt_copy_key (crypt_key_t *key) { crypt_key_t *k; - k = mem_calloc (1, sizeof *k); + k = p_new(crypt_key_t, 1); k->kobj = key->kobj; gpgme_key_ref (key->kobj); k->idx = key->idx; @@ -233,7 +233,7 @@ static void crypt_free_key (crypt_key_t ** keylist) while (*keylist) { crypt_key_t *k = (*keylist)->next; - mem_free (&k); + p_delete(&k); *keylist = k; } } @@ -560,7 +560,7 @@ static gpgme_key_t *create_recipient_set (const char *keylist, else { mutt_error (_("error adding recipient `%s': %s\n"), buf, gpgme_strerror (err)); - mem_free (&rset); + p_delete(&rset); return NULL; } } @@ -836,13 +836,13 @@ BODY *pgp_gpgme_encrypt_message (BODY * a, char *keylist, int sign) convert_to_7bit (a); plaintext = body_to_data_object (a, 0); if (!plaintext) { - mem_free (&rset); + p_delete(&rset); return NULL; } outfile = encrypt_gpgme_object (plaintext, rset, 0, sign); gpgme_data_release (plaintext); - mem_free (&rset); + p_delete(&rset); if (!outfile) return NULL; @@ -894,13 +894,13 @@ BODY *smime_gpgme_build_smime_entity (BODY * a, char *keylist) plaintext = body_to_data_object (a, 0); if (!plaintext) { - mem_free (&rset); + p_delete(&rset); return NULL; } outfile = encrypt_gpgme_object (plaintext, rset, 1, 0); gpgme_data_release (plaintext); - mem_free (&rset); + p_delete(&rset); if (!outfile) return NULL; @@ -1034,7 +1034,7 @@ static void show_fingerprint (gpgme_key_t key, STATE * state) return; is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP); - buf = mem_malloc (str_len (prefix) + str_len (s) * 4 + 2); + buf = xmalloc(str_len (prefix) + str_len (s) * 4 + 2); strcpy (buf, prefix); /* __STRCPY_CHECKED__ */ p = buf + str_len (buf); if (is_pgp && str_len (s) == 40) { /* PGP v4 style formatted. */ @@ -1064,7 +1064,7 @@ static void show_fingerprint (gpgme_key_t key, STATE * state) *p++ = '\n'; *p = 0; state_attach_puts (buf, state); - mem_free (&buf); + p_delete(&buf); } /* Show the valididy of a key used for one signature. */ @@ -1729,7 +1729,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset) if (!fname) return; unlink (fname); - mem_free (&fname); + p_delete(&fname); fc = fgetconv_open (fp, charset, Charset, M_ICONV_HOOK_FROM); @@ -1922,7 +1922,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s) } else { unlink (tmpfname); - mem_free (&tmpfname); + p_delete(&tmpfname); } } gpgme_release (ctx); @@ -2541,10 +2541,8 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, n = s - string; if (!n) return NULL; /* empty key */ - array->key = mem_malloc (n + 1); + array->key = p_dupstr(string, n ); p = (unsigned char *) array->key; - memcpy (p, string, n); /* fixme: trim trailing spaces */ - p[n] = 0; string = s + 1; if (*string == '#') { /* hexstring */ @@ -2555,7 +2553,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, if (!n || (n & 1)) return NULL; /* empty or odd number of digits */ n /= 2; - p = mem_malloc (n + 1); + p = xmalloc(n + 1); array->value = (char *) p; for (s1 = string; n; s1 += 2, n--) *p++ = xtoi_2 (s1); @@ -2585,7 +2583,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, n++; } - p = mem_malloc (n + 1); + p = xmalloc(n + 1); array->value = (char *) p; for (s = string; n; s++, n--) { if (*s == '\\') { @@ -2616,7 +2614,7 @@ static struct dn_array_s *parse_dn (const unsigned char *string) int i; arraysize = 7; /* C,ST,L,O,OU,CN,email */ - array = mem_malloc ((arraysize + 1) * sizeof *array); + array = p_new(struct dn_array_s, arraysize + 1); arrayidx = 0; while (*string) { while (*string == ' ') @@ -2627,12 +2625,12 @@ static struct dn_array_s *parse_dn (const unsigned char *string) struct dn_array_s *a2; arraysize += 5; - a2 = mem_malloc ((arraysize + 1) * sizeof *array); + a2 = p_new(struct dn_array_s, arraysize + 1); for (i = 0; i < arrayidx; i++) { a2[i].key = array[i].key; a2[i].value = array[i].value; } - mem_free (&array); + p_delete(&array); array = a2; } array[arrayidx].key = NULL; @@ -2654,10 +2652,10 @@ static struct dn_array_s *parse_dn (const unsigned char *string) failure: for (i = 0; i < arrayidx; i++) { - mem_free (&array[i].key); - mem_free (&array[i].value); + p_delete(&array[i].key); + p_delete(&array[i].value); } - mem_free (&array); + p_delete(&array); return NULL; } @@ -2688,10 +2686,10 @@ static void parse_and_print_user_id (FILE * fp, const char *userid) else { print_dn_parts (fp, dn); for (i = 0; dn[i].key; i++) { - mem_free (&dn[i].key); - mem_free (&dn[i].value); + p_delete(&dn[i].key); + p_delete(&dn[i].value); } - mem_free (&dn); + p_delete(&dn); } } } @@ -3039,7 +3037,7 @@ static char *list_to_pattern (LIST * list) n++; /* delimiter or end of string */ } n++; /* make sure to allocate at least one byte */ - pattern = p = mem_calloc (1, n); + pattern = p = p_new(char, n); for (l = list; l; l = l->next) { s = l->data; if (*s) { @@ -3087,7 +3085,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, err = gpgme_new (&ctx); if (err) { mutt_error (_("gpgme_new failed: %s"), gpgme_strerror (err)); - mem_free (&pattern); + p_delete(&pattern); return NULL; } @@ -3110,7 +3108,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, if (!n) goto no_pgphints; - patarr = mem_calloc (n + 1, sizeof *patarr); + patarr = p_new(char *, n + 1); for (l = hints, n = 0; l; l = l->next) { if (l->data && *l->data) patarr[n++] = str_dup (l->data); @@ -3118,12 +3116,12 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, patarr[n] = NULL; err = gpgme_op_keylist_ext_start (ctx, (const char **) patarr, secret, 0); for (n = 0; patarr[n]; n++) - mem_free (&patarr[n]); - mem_free (&patarr); + p_delete(&patarr[n]); + p_delete(&patarr); if (err) { mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err)); gpgme_release (ctx); - mem_free (&pattern); + p_delete(&pattern); return NULL; } @@ -3156,7 +3154,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, #endif /* DISABLED code */ for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = mem_calloc (1, sizeof *k); + k = p_new(crypt_key_t, 1); k->kobj = key; k->idx = idx; k->uid = uid->uid; @@ -3179,7 +3177,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, if (err) { mutt_error (_("gpgme_op_keylist_start failed: %s"), gpgme_strerror (err)); gpgme_release (ctx); - mem_free (&pattern); + p_delete(&pattern); return NULL; } @@ -3192,7 +3190,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, flags |= KEYFLAG_CANSIGN; for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = mem_calloc (1, sizeof *k); + k = p_new(crypt_key_t, 1); k->kobj = key; k->idx = idx; k->uid = uid->uid; @@ -3207,7 +3205,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, } gpgme_release (ctx); - mem_free (&pattern); + p_delete(&pattern); return db; } @@ -3227,7 +3225,7 @@ static LIST *crypt_add_string_to_hints (LIST * hints, const char *str) hints = mutt_add_list (hints, t); } - mem_free (&scratch); + p_delete(&scratch); return hints; } @@ -3419,7 +3417,7 @@ static crypt_key_t *crypt_select_key (crypt_key_t * keys, } mutt_menuDestroy (&menu); - mem_free (&key_table); + p_delete(&key_table); set_option (OPTNEEDREDRAW); @@ -3640,7 +3638,7 @@ static crypt_key_t *crypt_ask_for_key (char *tag, if (l) str_replace (&l->dflt, resp); else { - l = mem_malloc (sizeof (struct crypt_cache)); + l = p_new(struct crypt_cache, 1); l->next = id_defaults; id_defaults = l; l->what = str_dup (whatfor); @@ -3731,7 +3729,7 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc, } } else if (r == -1) { - mem_free (&keylist); + p_delete(&keylist); rfc822_free_address (&tmp); rfc822_free_address (&addr); return NULL; @@ -3750,7 +3748,7 @@ static char *find_keys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc, app, #endif &forced_valid)) == NULL) { - mem_free (&keylist); + p_delete(&keylist); rfc822_free_address (&tmp); rfc822_free_address (&addr); return NULL;