From: Andre Noll Date: Tue, 10 Apr 2012 05:38:20 +0000 (+0200) Subject: flacdec_close(): Be liberal in what you accept. X-Git-Tag: v0.4.11~13^2~2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=1e196821cc4fa9e1319557ce1100961be6795278;p=paraslash.git 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. --- 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; }