prepare for the release of rrdtool-1.2.19
[rrdtool.git] / src / rrd_error.c
index 33d7c2f..91ebdde 100644 (file)
@@ -1,10 +1,14 @@
 /*****************************************************************************
- * RRDtool 1.1.x  Copyright Tobias Oetiker, 1997 - 2002
+ * RRDtool 1.2.19  Copyright by Tobi Oetiker, 1997-2007
  *****************************************************************************
  * rrd_error.c   Common Header File
  *****************************************************************************
  * $Id$
  * $Log$
+ * Revision 1.4  2003/02/22 21:57:03  oetiker
+ * a patch to avoid a memory leak and a Makefile.am patch to
+ * distribute all required source files -- Peter Stamfest <peter@stamfest.at>
+ *
  * Revision 1.3  2003/02/13 07:05:27  oetiker
  * Find attached the patch I promised to send to you. Please note that there
  * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c
@@ -76,6 +80,7 @@ rrd_set_error_r(struct rrd_context *rrd_ctx, char *fmt, ...)
     va_start(argp, fmt);
 #ifdef HAVE_VSNPRINTF
     vsnprintf((char *)rrd_ctx->rrd_error, rrd_ctx->len, fmt, argp);
+    rrd_ctx->rrd_error[rrd_ctx->len]='\0';
 #else
     vsprintf((char *)rrd_ctx->rrd_error, fmt, argp);
 #endif
@@ -106,9 +111,8 @@ rrd_new_context(void) {
        (struct rrd_context *) malloc(sizeof(struct rrd_context));
 
     if (rrd_ctx) {
-       rrd_ctx->len = 0;
-       rrd_ctx->rrd_error = malloc(MAXLEN);
-       rrd_ctx->lib_errstr = malloc(ERRBUFLEN);
+       rrd_ctx->rrd_error = malloc(MAXLEN+10);
+       rrd_ctx->lib_errstr = malloc(ERRBUFLEN+10);
        if (rrd_ctx->rrd_error && rrd_ctx->lib_errstr) {
            *rrd_ctx->rrd_error = 0;
            *rrd_ctx->lib_errstr = 0;
@@ -127,6 +131,7 @@ void
 rrd_free_context(struct rrd_context *rrd_ctx) {
     if (rrd_ctx) {
        if (rrd_ctx->rrd_error) free(rrd_ctx->rrd_error);
+       if (rrd_ctx->lib_errstr) free(rrd_ctx->lib_errstr);
        free(rrd_ctx);
     }
 }