Rewrote the OSRF_MALLOC macro so that it evaluates each
authorscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 7 Jan 2009 18:28:53 +0000 (18:28 +0000)
committerscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 7 Jan 2009 18:28:53 +0000 (18:28 +0000)
of its arguments only once.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1578 9efc2488-bf62-4759-914b-345cdb29e865

include/opensrf/utils.h

index ab24e8f..ae2a7ee 100644 (file)
@@ -33,13 +33,15 @@ GNU General Public License for more details.
 
 #define OSRF_MALLOC(ptr, size) \
        do {\
-               ptr = (void*) malloc( size ); \
-               if( ptr == NULL ) { \
-                       perror("OSRF_MALLOC(): Out of Memory" );\
-                       exit(99); \
-               } \
-               memset( ptr, 0, size );\
-       } while(0)
+                       size_t _size = size; \
+                       void* p = malloc( _size ); \
+                       if( p == NULL ) { \
+                               perror("OSRF_MALLOC(): Out of Memory" ); \
+                               exit(99); \
+                       } \
+                       memset( p, 0, _size ); \
+                       (ptr) = p; \
+               } while(0)
 
 #ifdef NDEBUG
 // The original ... replace with noop once no more errors occur in NDEBUG mode