X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=miscutil.c;h=ea2c3aae18a9e3d9fef7f98200bdb1c2ed4f8876;hb=0fe4806b7b84868ace1fe044fae69e1d4e39d4b6;hp=f5e647caf377292e65e46bef4b38f14ee423b5c5;hpb=d2170158936d131cf7ec7ce95795d6347ceb93f9;p=privoxy.git diff --git a/miscutil.c b/miscutil.c index f5e647ca..ea2c3aae 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.80 2016/01/16 12:33:36 fabiankeil Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.83 2017/05/04 14:34:18 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -71,22 +71,27 @@ const char miscutil_h_rcs[] = MISCUTIL_H_VERSION; * * Function : zalloc * - * Description : Malloc some memory and set it to '\0'. + * Description : Returns allocated memory that is initialized + * with zeros. * * Parameters : * 1 : size = Size of memory chunk to return. * - * Returns : Pointer to newly malloc'd memory chunk. + * Returns : Pointer to newly alloc'd memory chunk. * *********************************************************************/ void *zalloc(size_t size) { void * ret; +#ifdef HAVE_CALLOC + ret = calloc(1, size); +#else if ((ret = (void *)malloc(size)) != NULL) { memset(ret, 0, size); } +#endif return(ret); @@ -765,7 +770,9 @@ long int pick_from_range(long int range) if (range <= 0) return 0; -#ifdef HAVE_RANDOM +#ifdef HAVE_ARC4RANDOM + number = arc4random() % range + 1; +#elif defined(HAVE_RANDOM) number = random() % range + 1; #elif defined(MUTEX_LOCKS_AVAILABLE) privoxy_mutex_lock(&rand_mutex); @@ -789,7 +796,7 @@ long int pick_from_range(long int range) "might cause crashes, predictable results or even combine these fine options."); number = rand() % (long int)(range + 1); -#endif /* (def HAVE_RANDOM) */ +#endif /* (def HAVE_ARC4RANDOM) */ return number; } @@ -893,6 +900,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 */ }