Handle correctly some malloc failures.

This commit is contained in:
Giuseppe Scrivano 2012-02-23 11:45:05 +01:00
parent 611a219fb0
commit bcc2abf116
2 changed files with 20 additions and 8 deletions

View File

@ -1,5 +1,7 @@
2012-02-23 Giuseppe Scrivano <giuseppe@southpole.se>
* main.c (main): Fail gracefully if `malloc' fails.
* gnutls.c (wgnutls_read): Remove unused variables `timer' and `flags'.
2012-02-17 Steven Schubiger <stsc@member.fsf.org>

View File

@ -988,15 +988,20 @@ main (int argc, char **argv)
for (i = 1; i < argc; i++)
argstring_length += strlen (argv[i]) + 2 + 1;
char *p = program_argstring = malloc (argstring_length * sizeof (char));
if (p == NULL)
{
fprintf (stderr, _("Memory allocation problem\n"));
exit (2);
}
for (i = 1; i < argc; i++)
{
*p++ = '"';
int arglen = strlen (argv[i]);
memcpy (p, argv[i], arglen);
p += arglen;
*p++ = '"';
*p++ = ' ';
}
{
*p++ = '"';
int arglen = strlen (argv[i]);
memcpy (p, argv[i], arglen);
p += arglen;
*p++ = '"';
*p++ = ' ';
}
*p = '\0';
/* Load the hard-coded defaults. */
@ -1355,6 +1360,11 @@ for details.\n\n"));
/* Fill in the arguments. */
url = alloca_array (char *, nurl + 1);
if (url == NULL)
{
fprintf (stderr, _("Memory allocation problem\n"));
exit (2);
}
for (i = 0; i < nurl; i++, optind++)
{
char *rewritten = rewrite_shorthand_url (argv[optind]);