$OpenBSD: patch-src_wavlike_c,v 1.1 2021/01/16 12:54:12 sthen Exp $

- Fix leak in wavlike_read_cart_chunk.
- Fix memory leak in wavlike_read_peak_chunk.
- Fix use of uninitialized value in exif_subchunk_parse.

Index: src/wavlike.c
--- src/wavlike.c.orig
+++ src/wavlike.c
@@ -838,6 +838,12 @@ wavlike_read_cart_chunk (SF_PRIVATE *psf, uint32_t chu
 
 	psf_log_printf (psf, "cart : %u\n", chunksize) ;
 
+	if (psf->cart_16k)
+	{	psf_log_printf (psf, "  Found more than one cart chunk, using last one.\n") ;
+		free (psf->cart_16k) ;
+		psf->cart_16k = NULL ;
+		} ;
+
 	if ((psf->cart_16k = cart_var_alloc ()) == NULL)
 	{	psf->error = SFE_MALLOC_FAILED ;
 		return psf->error ;
@@ -1187,6 +1193,11 @@ wavlike_read_peak_chunk (SF_PRIVATE * psf, size_t chun
 		return SFE_WAV_BAD_PEAK ;
 		} ;
 
+	if (psf->peak_info)
+	{	psf_log_printf (psf, "*** Found existing peak info, using last one.\n") ;
+		free (psf->peak_info) ;
+		psf->peak_info = NULL ;
+		} ;
 	if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
 		return SFE_MALLOC_FAILED ;
 
@@ -1258,7 +1269,7 @@ exif_fill_and_sink (SF_PRIVATE *psf, char* buf, size_t
 */
 static int
 exif_subchunk_parse (SF_PRIVATE *psf, uint32_t length)
-{	uint32_t marker, dword, vmajor = -1, vminor = -1, bytesread = 0 ;
+{	uint32_t marker, dword = 0, vmajor = -1, vminor = -1, bytesread = 0 ;
 	char buf [4096] ;
 	int thisread ;
 
