On 12/22/2014 11:14 PM, Eric Wong wrote:
> Pander <pan...@users.sourceforge.net> wrote:
>> Please review the attached patch for outputting the average power spectrum.
> 
> I am not knowledgable in the math behind this, but I noticed one
> memory management error:
> 
>> @@ -134,6 +138,15 @@ static int sox_stat_flow(sox_effect_t * effp, const 
>> sox_sample_t *ibuf, sox_samp
>>    priv_t * stat = (priv_t *) effp->priv;
>>    int done, x, len = min(*isamp, *osamp);
>>    short count = 0;
>> +  float *re_average;
> 
> re_average needs to be initialized for the "stat->fft_average != 1" case
> 
>   float *re_average = NULL;

Thanks, that will also remove a warning.

Please see the attachement for the incremental patch.

The first patch also included some of the changes coming in with the
promoted git pull in http://sox.sourceforge.net/ but git can split them
in the patch for the maintainer.

> 
>> +  if (stat->fft_average == 1) {
>> +      samples = (stat->fft_size / 2);
>> +      ffa = effp->in_signal.rate / samples;
>> +      re_average = lsx_malloc(sizeof(float) * (int)samples);
>> +  }
> 
> ...otherwise, free may be called on an uninitialized value:
> 
>> +  if (re_average) {
>> +    free(re_average);
>> +  }
>>    *isamp = *osamp = len;
>>    /* Process all samples */
> 
> There's also a bunch of unrelated whitespace eliminations
> in the manpage which should probably be a separate commit
> (but I'm not a sox maintainer, just another user + occasional patcher).
> 
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming! The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net
> _______________________________________________
> SoX-devel mailing list
> SoX-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sox-devel
> 

>From 94c0f9125b77f0f9a678c9766330e7e55b5ec546 Mon Sep 17 00:00:00 2001
From: Pander <pan...@users.sourceforge.net>
Date: Mon, 22 Dec 2014 23:56:37 +0100
Subject: [PATCH] Im proved memory management

---
 src/stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/stat.c b/src/stat.c
index 63d1741..0ce8415 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -138,7 +138,7 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp
   priv_t * stat = (priv_t *) effp->priv;
   int done, x, len = min(*isamp, *osamp);
   short count = 0;
-  float *re_average;
+  float *re_average = NULL;
   unsigned samples = 0;
   float ffa = 0.0;
   unsigned i;
-- 
2.1.0

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

Reply via email to