Index: src/io/source.c
===================================================================
--- src/io/source.c	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source.c	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -42,4 +42,5 @@
 typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
 typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
+typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
 typedef void (*del_aubio_source_t)(aubio_source_t * s);
 
@@ -51,4 +52,5 @@
   aubio_source_get_channels_t s_get_channels;
   aubio_source_seek_t s_seek;
+  aubio_source_close_t s_close;
   del_aubio_source_t s_del;
 };
@@ -64,4 +66,5 @@
     s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
     s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
+    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
     s->s_del = (del_aubio_source_t)(del_aubio_source_avcodec);
     return s;
@@ -76,4 +79,5 @@
     s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
     s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
+    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
     s->s_del = (del_aubio_source_t)(del_aubio_source_apple_audio);
     return s;
@@ -88,4 +92,5 @@
     s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
     s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
+    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
     s->s_del = (del_aubio_source_t)(del_aubio_source_sndfile);
     return s;
@@ -100,4 +105,5 @@
     s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
     s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
+    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
     s->s_del = (del_aubio_source_t)(del_aubio_source_wavread);
     return s;
@@ -116,4 +122,8 @@
 void aubio_source_do_multi(aubio_source_t * s, fmat_t * data, uint_t * read) {
   s->s_do_multi((void *)s->source, data, read);
+}
+
+uint_t aubio_source_close(aubio_source_t * s) {
+  return s->s_close((void *)s->source);
 }
 
Index: src/io/source.h
===================================================================
--- src/io/source.h	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source.h	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -142,4 +142,15 @@
 /**
 
+  close source object
+
+  \param s source object, created with ::new_aubio_source
+
+  \return 0 if sucessful, non-zero on failure
+
+ */
+uint_t aubio_source_close (aubio_source_t *s);
+
+/**
+
   close source and cleanup memory
 
Index: src/io/source_apple_audio.c
===================================================================
--- src/io/source_apple_audio.c	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_apple_audio.c	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -258,5 +258,5 @@
 {
   OSStatus err = noErr;
-  if (!s || !s->audioFile) { return AUBIO_FAIL; }
+  if (!s->audioFile) { return AUBIO_FAIL; }
   err = ExtAudioFileDispose(s->audioFile);
   s->audioFile = NULL;
Index: src/io/source_apple_audio.h
===================================================================
--- src/io/source_apple_audio.h	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_apple_audio.h	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -122,4 +122,15 @@
 /**
 
+  close source
+
+  \param s source object, created with ::new_aubio_source_apple_audio
+
+  \return 0 if sucessful, non-zero on failure
+
+*/
+uint_t aubio_source_apple_audio_close(aubio_source_apple_audio_t * s);
+
+/**
+
   close source and cleanup memory
 
Index: src/io/source_avcodec.c
===================================================================
--- src/io/source_avcodec.c	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_avcodec.c	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -391,9 +391,5 @@
 }
 
-void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
-  if (!s) return;
-  if (s->output != NULL) {
-    av_free(s->output);
-  }
+uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
   if (s->avr != NULL) {
     avresample_close( s->avr );
@@ -401,8 +397,4 @@
   }
   s->avr = NULL;
-  if (s->avFrame != NULL) {
-    avcodec_free_frame( &(s->avFrame) );
-  }
-  s->avFrame = NULL;
   if (s->avCodecCtx != NULL) {
     avcodec_close ( s->avCodecCtx );
@@ -412,6 +404,19 @@
     avformat_close_input ( &(s->avFormatCtx) );
   }
+  s->avFormatCtx = NULL;
+  return AUBIO_OK;
+}
+
+void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
+  if (!s) return;
+  aubio_source_avcodec_close(s);
+  if (s->output != NULL) {
+    av_free(s->output);
+  }
+  s->output = NULL;
+  if (s->avFrame != NULL) {
+    avcodec_free_frame( &(s->avFrame) );
+  }
   s->avFrame = NULL;
-  s->avFormatCtx = NULL;
   AUBIO_FREE(s);
 }
Index: src/io/source_avcodec.h
===================================================================
--- src/io/source_avcodec.h	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_avcodec.h	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -121,4 +121,15 @@
 /**
 
+  close source
+
+  \param s source object, created with ::new_aubio_source_avcodec
+
+  \return 0 if sucessful, non-zero on failure
+
+*/
+uint_t aubio_source_avcodec_close (aubio_source_avcodec_t *s);
+
+/**
+
   close source and cleanup memory
 
Index: src/io/source_sndfile.c
===================================================================
--- src/io/source_sndfile.c	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_sndfile.c	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -268,9 +268,17 @@
 }
 
+uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) {
+  if (!s->handle) {
+    return AUBIO_FAIL;
+  if(sf_close(s->handle)) {
+    AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
+    return AUBIO_FAIL;
+  }
+  return AUBIO_OK;
+}
+
 void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
   if (!s) return;
-  if (sf_close(s->handle)) {
-    AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
-  }
+  aubio_source_sndfile_close(s):
 #ifdef HAVE_SAMPLERATE
   if (s->resampler != NULL) {
Index: src/io/source_sndfile.h
===================================================================
--- src/io/source_sndfile.h	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_sndfile.h	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -121,4 +121,15 @@
 /**
 
+  close source
+
+  \param s source object, created with ::new_aubio_source_sndfile
+
+  \return 0 if sucessful, non-zero on failure
+
+*/
+uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s);
+
+/**
+
   close source and cleanup memory
 
Index: src/io/source_wavread.c
===================================================================
--- src/io/source_wavread.c	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_wavread.c	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -347,7 +347,14 @@
 }
 
+uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
+  if (!s->fid || fclose(s->fid)) {
+    return AUBIO_FAIL;
+  }
+  return AUBIO_OK;
+}
+
 void del_aubio_source_wavread(aubio_source_wavread_t * s) {
   if (!s) return;
-  if (s->fid) fclose(s->fid);
+  aubio_source_wavread_close(s);
   if (s->short_output) AUBIO_FREE(s->short_output);
   if (s->output) del_fmat(s->output);
Index: src/io/source_wavread.h
===================================================================
--- src/io/source_wavread.h	(revision a9fd272915d06287c5e0b9384c383fb1468ddb60)
+++ src/io/source_wavread.h	(revision 422452b4197a513d074c45701419fb58816c99e6)
@@ -126,4 +126,15 @@
 /**
 
+  close source
+
+  \param s source object, created with ::new_aubio_source_wavread
+
+  \return 0 if sucessful, non-zero on failure
+
+*/
+uint_t aubio_source_wavread_close (aubio_source_wavread_t *s);
+
+/**
+
   close source and cleanup memory
 
