]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
flacdec_close(): Be liberal in what you accept.
authorAndre Noll <maan@systemlinux.org>
Tue, 10 Apr 2012 05:38:20 +0000 (07:38 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 3 Jun 2012 11:04:01 +0000 (13:04 +0200)
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

index 40246f24b625c3a5236df47149bb9179633eb5f9..cd086f45748b9f85155f624f40fa1c939daf7cae 100644 (file)
@@ -264,10 +264,17 @@ out:
 
 static void flacdec_close(struct filter_node *fn)
 {
 
 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;
 }
        free(pfd);
        fn->private_data = NULL;
 }