From 055f23ee3692349a03f681ef1a0d5fd70c0cc770 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 9 Mar 2010 09:53:07 +0100 Subject: [PATCH] wrbuf_destroy allows NULL WRBUF passed to it --- include/yaz/wrbuf.h | 2 ++ src/wrbuf.c | 7 +++++-- test/tstwrbuf.c | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) 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(); -- 1.7.10.4