1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-03 12:11:33 +01:00

common: Use new function to print a failure of xtrymalloc.

* common/miscellaneous.c (xoutofcore): New.
* common/strlist.c (append_to_strlist): Use instead of abort.
(append_to_strlist_try): Use xtrymalloc instead of xmalloc.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-04-25 17:26:57 +02:00
parent b8cb0973bc
commit 8776abbe02
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 17 additions and 3 deletions

View File

@ -106,6 +106,17 @@ setup_libgcrypt_logging (void)
} }
/* Print an out of core message and let the process die. The printed
* error is taken from ERRNO. */
void
xoutofcore (void)
{
gpg_error_t err = gpg_error_from_syserror ();
log_fatal (_("error allocating enough memory: %s\n"), gpg_strerror (err));
abort (); /* Never called; just to make the compiler happy. */
}
/* A wrapper around gcry_cipher_algo_name to return the string /* A wrapper around gcry_cipher_algo_name to return the string
"AES-128" instead of "AES". Given that we have an alias in "AES-128" instead of "AES". Given that we have an alias in
libgcrypt for it, it does not harm to too much to return this other libgcrypt for it, it does not harm to too much to return this other

View File

@ -128,8 +128,8 @@ append_to_strlist( strlist_t *list, const char *string )
{ {
strlist_t sl; strlist_t sl;
sl = append_to_strlist_try (list, string); sl = append_to_strlist_try (list, string);
if (sl == NULL) if (!sl)
abort (); xoutofcore ();
return sl; return sl;
} }
@ -140,7 +140,7 @@ append_to_strlist_try (strlist_t *list, const char *string)
{ {
strlist_t r, sl; strlist_t r, sl;
sl = xmalloc( sizeof *sl + strlen(string)); sl = xtrymalloc( sizeof *sl + strlen(string));
if (sl == NULL) if (sl == NULL)
return NULL; return NULL;

View File

@ -263,6 +263,9 @@ const char *gnupg_messages_locale_name (void);
logging subsystem. */ logging subsystem. */
void setup_libgcrypt_logging (void); void setup_libgcrypt_logging (void);
/* Print an out of core emssage and die. */
void xoutofcore (void);
/* Same as estream_asprintf but die on memory failure. */ /* Same as estream_asprintf but die on memory failure. */
char *xasprintf (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2); char *xasprintf (const char *fmt, ...) GPGRT_ATTR_PRINTF(1,2);
/* This is now an alias to estream_asprintf. */ /* This is now an alias to estream_asprintf. */