I'm curious why the xmalloc() function (and its brethren) exits with a
fatal error on only some systems and not on all systems?  I would think
that the code should use the exiting functions in all cases, and just
provide differing versions of xstrdup() so that the HAVE_MCHECK_H
version does a malloc() (rather than strdup() doing it).

If I'm not off track, you can apply the attached patch to implement
this.

..wayne..
--- system.h    9 Mar 2008 20:24:45 -0000       1.14
+++ system.h    9 Mar 2008 23:01:40 -0000
@@ -77,19 +77,17 @@ static inline char * stpcpy (char *dest,
 }
 #endif
 
-/* Memory allocation via macro defs to get meaningful locations from mtrace() 
*/
-#if defined(HAVE_MCHECK_H) && defined(__GNUC__)
+/* Error-checking versions of common memory-allocation functions. */
 #define        vmefail()       (fprintf(stderr, "virtual memory 
exhausted.\n"), exit(EXIT_FAILURE), NULL)
 #define        xmalloc(_size)          (malloc(_size) ? : vmefail())
 #define        xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : 
vmefail())
 #define        xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail())
+/* Avoid strdup() to get meaningful locations from mtrace() */
+#if defined(HAVE_MCHECK_H) && defined(__GNUC__)
 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail()), 
(_str)))
 #else
-#define        xmalloc(_size)          malloc(_size)
-#define        xcalloc(_nmemb, _size)  calloc((_nmemb), (_size))
-#define        xrealloc(_ptr, _size)   realloc((_ptr), (_size))
-#define        xstrdup(_str)   strdup(_str)
-#endif  /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
+#define xstrdup(_str)   (strdup(_str) ? : vmefail())
+#endif
 
 #if defined(HAVE___SECURE_GETENV) && !defined(__LCLINT__)
 #define        getenv(_s)      __secure_getenv(_s)

Reply via email to