X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=mem.c;h=f8ee8855b98d635af3982e28f94247dd7c255934;hb=edb6ab7ea99d663f55466610ca7678af2c0fadd3;hp=90ab67c7201d97dd9bb116999745b61d5e7b638d;hpb=6ddbb3991cc5ad6089410078695f574b2bd8388e;p=ir-tcl-moved-to-github.git diff --git a/mem.c b/mem.c index 90ab67c..f8ee885 100644 --- a/mem.c +++ b/mem.c @@ -1,11 +1,20 @@ /* * IR toolkit for tcl/tk - * (c) Index Data 1995 + * (c) Index Data 1995-1998 * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: mem.c,v $ - * Revision 1.1 1995-08-04 11:32:40 adam + * Revision 1.4 1998-10-13 21:23:37 adam + * Fixed log message. + * + * Revision 1.3 1996/07/03 13:31:14 adam + * The xmalloc/xfree functions from YAZ are used to manage memory. + * + * Revision 1.2 1995/08/29 15:30:15 adam + * Work on GRS records. + * + * Revision 1.1 1995/08/04 11:32:40 adam * More work on output queue. Memory related routines moved * to mem.c * @@ -23,7 +32,7 @@ */ void *ir_tcl_malloc (size_t n) { - void *p = malloc (n); + void *p = xmalloc (n); if (!p) { logf (LOG_FATAL, "Out of memory. %ld bytes requested", (long) n); @@ -37,14 +46,22 @@ void *ir_tcl_malloc (size_t n) */ int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s) { + size_t len; + if (!s) { *p = NULL; return TCL_OK; } - *p = malloc (strlen(s)+1); + len = strlen(s)+1; + *p = xmalloc (len); if (!*p) { + if (!interp) + { + logf (LOG_FATAL, "Out of memory in strdup. %d bytes", len); + exit (1); + } interp->result = "strdup fail"; return TCL_ERROR; } @@ -57,7 +74,7 @@ int ir_tcl_strdup (Tcl_Interp *interp, char** p, const char *s) */ int ir_tcl_strdel (Tcl_Interp *interp, char **p) { - free (*p); + xfree (*p); *p = NULL; return TCL_OK; }