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.
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;
}