From 1e196821cc4fa9e1319557ce1100961be6795278 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 10 Apr 2012 07:38:20 +0200 Subject: [PATCH] flacdec_close(): Be liberal in what you accept. Functions like close() which terminate an instance of some subsystem should always be idempotent, i.e. when calling such a function twice with the same argument, the second call should be a noop. However, flacdec_close() violates this rule because it dereferences its private pointer unconditionally. This patch makes the function idempotent. --- flacdec_filter.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flacdec_filter.c b/flacdec_filter.c index 40246f24..cd086f45 100644 --- a/flacdec_filter.c +++ b/flacdec_filter.c @@ -264,10 +264,17 @@ out: static void flacdec_close(struct filter_node *fn) { - struct private_flacdec_data *pfd = fn->private_data; + struct private_flacdec_data *pfd; - FLAC__stream_decoder_finish(pfd->decoder); - FLAC__stream_decoder_delete(pfd->decoder); + if (!fn) + return; + pfd = fn->private_data; + if (!pfd) + return; + if (pfd->decoder) { + FLAC__stream_decoder_finish(pfd->decoder); + FLAC__stream_decoder_delete(pfd->decoder); + } free(pfd); fn->private_data = NULL; } -- 2.39.5