From: Adam Dickmeiss Date: Tue, 9 Mar 2010 08:53:07 +0000 (+0100) Subject: wrbuf_destroy allows NULL WRBUF passed to it X-Git-Tag: v4.0.2~2 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=055f23ee3692349a03f681ef1a0d5fd70c0cc770;p=yaz-moved-to-github.git wrbuf_destroy allows NULL WRBUF passed to it --- diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 46b38f5..0f393a6 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -53,6 +53,8 @@ YAZ_EXPORT WRBUF wrbuf_alloc(void); /** \brief destroy WRBUF and its buffer \param b WRBUF + + For YAZ 4.0.2 WRBUF b may be NULL. */ YAZ_EXPORT void wrbuf_destroy(WRBUF b); diff --git a/src/wrbuf.c b/src/wrbuf.c index e6c53e8..31729b0 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -35,8 +35,11 @@ WRBUF wrbuf_alloc(void) void wrbuf_destroy(WRBUF b) { - xfree(b->buf); - xfree(b); + if (b) + { + xfree(b->buf); + xfree(b); + } } void wrbuf_rewind(WRBUF b) diff --git a/test/tstwrbuf.c b/test/tstwrbuf.c index 8b94634..af06e40 100644 --- a/test/tstwrbuf.c +++ b/test/tstwrbuf.c @@ -12,10 +12,13 @@ static void tstwrbuf(void) { int step; - WRBUF wr = wrbuf_alloc(); + WRBUF wr; - YAZ_CHECK(wr); + wr = 0; + wrbuf_destroy(wr); + wr = wrbuf_alloc(); + YAZ_CHECK(wr); wrbuf_destroy(wr); wr = wrbuf_alloc();