current miscutil.c, 1.80, 1.81 miscutil.h, 1.37, 1.38

Fabian Keil <[email protected]>
Newsgroups gmane.comp.web.privoxy.cvs
Message-ID <[email protected]>
Update of /cvsroot/ijbswa/current
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv27171

Modified Files:
	miscutil.c miscutil.h 
Log Message:
Add zalloc_or_die()

... which will allow to simplify code paths were zalloc()
failures don't need to be handled gracefully.


Index: miscutil.h
===================================================================
RCS file: /cvsroot/ijbswa/current/miscutil.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** miscutil.h	24 Nov 2012 13:58:17 -0000	1.37
--- miscutil.h	26 Feb 2016 12:29:17 -0000	1.38
***************
*** 47,50 ****
--- 47,51 ----
  extern const char *basedir;
  extern void *zalloc(size_t size);
+ extern void *zalloc_or_die(size_t size);
  extern char *strdup_or_die(const char *str);
  extern void *malloc_or_die(size_t buffer_size);

Index: miscutil.c
===================================================================
RCS file: /cvsroot/ijbswa/current/miscutil.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -C2 -d -r1.80 -r1.81
*** miscutil.c	16 Jan 2016 12:33:36 -0000	1.80
--- miscutil.c	26 Feb 2016 12:29:17 -0000	1.81
***************
*** 96,99 ****
--- 96,133 ----
  /*********************************************************************
   *
+  * 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
   *


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.