X-Git-Url: http://www.privoxy.org/gitweb/?a=blobdiff_plain;f=miscutil.c;h=bbfba611fc08a30a60f272c359c6dc57ba0f5e9b;hb=8eb9a5f57a8fa493b9486638cece8b3a9b72b9d2;hp=61ef5831b7d278b8996e94affb48f22bb0198660;hpb=8675bc0559b182e88e9dfbfd98cc9c9f8717cf0b;p=privoxy.git diff --git a/miscutil.c b/miscutil.c index 61ef5831..bbfba611 100644 --- a/miscutil.c +++ b/miscutil.c @@ -1,4 +1,4 @@ -const char miscutil_rcs[] = "$Id: miscutil.c,v 1.75 2012/03/09 16:24:36 fabiankeil Exp $"; +const char miscutil_rcs[] = "$Id: miscutil.c,v 1.76 2012/03/09 17:55:50 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/miscutil.c,v $ @@ -8,7 +8,7 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 1.75 2012/03/09 16:24:36 fabianke * to deserve their own file but don't really fit in * any other file. * - * Copyright : Written by and Copyright (C) 2001-2011 the + * Copyright : Written by and Copyright (C) 2001-2012 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -129,6 +129,42 @@ char *strdup_or_die(const char *str) } +/********************************************************************* + * + * Function : malloc_or_die + * + * Description : malloc wrapper that either succeeds or causes + * program termination. + * + * Useful in situations were the buffer size is "small" + * and malloc() failures couldn't be handled better + * anyway. In case of debug builds, failures trigger + * an assert(). + * + * Parameters : + * 1 : buffer_size = Size of the space to allocate + * + * Returns : Pointer to newly malloc'd memory + * + *********************************************************************/ +void *malloc_or_die(size_t buffer_size) +{ + char *new_buf; + + new_buf = malloc(buffer_size); + + if (new_buf == NULL) + { + assert(new_buf != NULL); + log_error(LOG_LEVEL_FATAL, "Out of memory in malloc_or_die()."); + exit(1); + } + + return(new_buf); + +} + + #if defined(unix) /********************************************************************* *