Binary files motion/.git/index and motion.cgr/.git/index differ
diff -rup motion/.git/logs/HEAD motion.cgr/.git/logs/HEAD
--- motion/.git/logs/HEAD	2014-12-16 11:24:10.733338687 +0100
+++ motion.cgr/.git/logs/HEAD	2014-11-28 16:15:08.149189838 +0100
@@ -1 +1 @@
-0000000000000000000000000000000000000000 ad7e243fcaee500f67297305d9235556fb4270b9 kmaster <kmaster@NVR01001.globalsp.com> 1418725450 +0100	clone: from https://github.com/sackmotion/motion.git
+0000000000000000000000000000000000000000 ad7e243fcaee500f67297305d9235556fb4270b9 kmaster <kmaster@NVR01001.globalsp.com> 1417187708 +0100	clone: from https://github.com/sackmotion/motion.git
diff -rup motion/.git/logs/refs/heads/master motion.cgr/.git/logs/refs/heads/master
--- motion/.git/logs/refs/heads/master	2014-12-16 11:24:10.733338687 +0100
+++ motion.cgr/.git/logs/refs/heads/master	2014-11-28 16:15:08.149189838 +0100
@@ -1 +1 @@
-0000000000000000000000000000000000000000 ad7e243fcaee500f67297305d9235556fb4270b9 kmaster <kmaster@NVR01001.globalsp.com> 1418725450 +0100	clone: from https://github.com/sackmotion/motion.git
+0000000000000000000000000000000000000000 ad7e243fcaee500f67297305d9235556fb4270b9 kmaster <kmaster@NVR01001.globalsp.com> 1417187708 +0100	clone: from https://github.com/sackmotion/motion.git
Binary files motion/.git/objects/pack/pack-37e2c86063e5c9e24fae24788adf709f4c64c0e1.idx and motion.cgr/.git/objects/pack/pack-37e2c86063e5c9e24fae24788adf709f4c64c0e1.idx differ
Binary files motion/.git/objects/pack/pack-37e2c86063e5c9e24fae24788adf709f4c64c0e1.pack and motion.cgr/.git/objects/pack/pack-37e2c86063e5c9e24fae24788adf709f4c64c0e1.pack differ
diff -rup motion/netcam.c motion.cgr/netcam.c
--- motion/netcam.c	2014-12-16 11:24:10.756339105 +0100
+++ motion.cgr/netcam.c	2014-12-16 10:02:23.663812633 +0100
@@ -2657,6 +2657,9 @@ void netcam_cleanup(netcam_context_ptr n
 
     if (netcam->response != NULL) 
         free(netcam->response);
+#ifdef have_av_get_media_type_string
+    netcam_shutdown_rtsp(netcam);
+#endif
 
     pthread_mutex_destroy(&netcam->mutex);
     pthread_cond_destroy(&netcam->cap_cond);
diff -rup motion/netcam_rtsp.c motion.cgr/netcam_rtsp.c
--- motion/netcam_rtsp.c	2014-12-16 11:24:10.757339123 +0100
+++ motion.cgr/netcam_rtsp.c	2014-12-16 10:14:45.632407781 +0100
@@ -149,6 +149,14 @@ static void rtsp_free_context(struct rts
   if (ctxt == NULL)
     return;
   
+  if (ctxt->codec_context != NULL) {
+    	avcodec_close(ctxt->codec_context);
+  }
+
+  if (ctxt->format_context != NULL) {
+    	avformat_close_input(&ctxt->format_context);
+  }
+  
   if (ctxt->path != NULL)
     free(ctxt->path);
   
@@ -157,15 +165,7 @@ static void rtsp_free_context(struct rts
   
   if (ctxt->pass)
     free(ctxt->pass);
-  
-  if (ctxt->format_context != NULL) {
-    	avformat_close_input(&ctxt->format_context);
-  }
-  
-  if (ctxt->codec_context != NULL) {
-    	avcodec_close(ctxt->codec_context);
-  }
-  
+   
   free(ctxt);
 }
 
@@ -258,6 +258,8 @@ int netcam_read_rtsp_image(netcam_contex
   if (size_decoded == 0) {
     // something went wrong, end of stream?
     MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: invalid frame!");
+    av_free_packet(&packet);
+    av_free(frame);
     return -1;
   }
 
