X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;h=10ff9ead4f58c2cd7d519964c46bf16b1ba9a2e4;hp=b468fc683798f0b338d5522e070db50f9d655aa9;hb=983ba27e15f4691702d498b14f6c1459254bcc78;hpb=d742e3533103cbd573cce873fc3b2bf112cece85 diff --git a/miscutil.c b/miscutil.c index b468fc68..10ff9ead 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.78 2012/11/24 13:58:17 fabiankeil Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.81 2016/02/26 12:29:17 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -8,7 +8,7 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.78 2012/11/24 13:58:17 fabianke * to deserve their own file but don't really fit in * any other file. * - * Copyright : Written by and Copyright (C) 2001-2012 the + * Copyright : Written by and Copyright (C) 2001-2016 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -93,6 +93,40 @@ void *zalloc(size_t size) } +/********************************************************************* + * + * Function : zalloc_or_die + * + * Description : zalloc wrapper that either succeeds or causes + * program termination. + * + * Useful in situations were the string length is + * "small" and zalloc() failures couldn't be handled + * better anyway. In case of debug builds, failures + * trigger an assert(). + * + * Parameters : + * 1 : size = Size of memory chunk to return. + * + * Returns : Pointer to newly malloc'd memory chunk. + * + *********************************************************************/ +void *zalloc_or_die(size_t size) +{ + void *buffer; + + buffer = zalloc(size); + if (buffer == NULL) + { + assert(buffer != NULL); + log_error(LOG_LEVEL_FATAL, "Out of memory in zalloc_or_die()."); + exit(1); + } + + return(buffer); + +} + /********************************************************************* * * Function : strdup_or_die @@ -859,6 +893,16 @@ time_t timegm(struct tm *tm) strcat(old_zone, zone); putenv(old_zone); #ifdef _WIN32 + /* http://man7.org/linux/man-pages/man3/putenv.3.html + * int putenv(char *string); + * The string pointed to by string becomes part of the environment, so altering the + * string changes the environment. + * In other words, the memory pointed to by *string is used until + * a) another call to putenv() with the same e-var name + * b) the program exits + * + * Windows e-vars don't work that way, so let's not leak memory. + */ free(old_zone); #endif /* def _WIN32 */ }