Below is the simple routine that calls fftw. Is there something in particular I need to watch out for when using with gnuradio to avoid the double free error? Thanks!

Grace

****
In probeExtract_impl.h:

   ...
   #include <pthread.h>
   #include "fftw3.h"

   #define NUM_FFTW_THREADS 2
   #define MAX_FFT_EXP 25

   using namespace std;

   namespace gr {
        namespace customModule {

            class probeExtract_impl : public probeExtract
            {
            private:
                typedef struct {
                    pthread_mutex_t fftw3_mutex =
   PTHREAD_MUTEX_INITIALIZER;
   ...

****
In probeExtract_impl.cc:

   ...
          void probeExtract_impl::ForwardFT (vector<gr_complex>
   &series, int M)
          {
              int exponent;
              fftwf_plan plans[MAX_FFT_EXP];

              exponent = (int) (log10((float) M)/log10(2.0) + 0.5);

              err_val = fftwf_init_threads ();
              if (err_val == 0)
                  throw runtime_error("fftwf_init_threads failed");
              fftwf_plan_with_nthreads(NUM_FFTW_THREADS);

              pthread_mutex_lock (&fftw3_mutex);

              fftwf_make_planner_thread_safe();

              plans[exponent] = fftwf_plan_dft_1d (M,
   reinterpret_cast<fftwf_complex *> (&series[0]),
   reinterpret_cast<fftwf_complex *> (&series[0]),
                                                   FFTW_FORWARD,
   FFTW_ESTIMATE);
              fftwf_execute (plans[exponent]);

              pthread_mutex_unlock (&fftw3_mutex);
              fftwf_destroy_plan (plans[exponent]);
              fftwf_cleanup_threads ();

              return;
          }


On 4/19/23 11:18, Grace Yeung wrote:

After some debugging, it appears grc is breaking inside of calls to fftw (see below). I am simply trying to use fftw to perform a simple FFT transform (forward/backward). Is there anything special I need to watch out for when using fftw with gnuradio? Any examples available? Any advice would be much appreciated. Thanks!

Backtracing shows the crash happens in an fftw3f library function used in the code...

(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 <https://github.com/gnuradio/gnuradio/pull/1>0x00007ffff7dd1859 in __GI_abort () at abort.c:79 #2 <https://github.com/gnuradio/gnuradio/pull/2>0x00007ffff7e3c26e in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7f66298 "%s\n") at ../sysdeps/posix/libc_fatal.c:155 #3 <https://github.com/gnuradio/gnuradio/pull/3>0x00007ffff7e442fc in malloc_printerr (str=str@entry=0x7ffff7f68628 "double free or corruption (fasttop)") at malloc.c:5347 #4 <https://github.com/gnuradio/gnuradio/pull/4>0x00007ffff7e45c65 in _int_free (av=0x7fffac000020, p=0x7fffac55a8d0, have_lock=0) at malloc.c:4266 #5 <https://github.com/gnuradio/gnuradio/pull/5>0x00007fffefe830d9 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #6 <https://github.com/gnuradio/gnuradio/pull/6>0x00007fffefe83c44 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #7 <https://github.com/gnuradio/gnuradio/pull/7>0x00007fffefe83fc4 in fftwf_mkplan_d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #8 <https://github.com/gnuradio/gnuradio/pull/8>0x00007fffefe88e5d in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #9 <https://github.com/gnuradio/gnuradio/pull/9>0x00007fffefe8380b in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #10 <https://github.com/gnuradio/gnuradio/pull/10>0x00007fffefe83a03 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #11 <https://github.com/gnuradio/gnuradio/pull/11>0x00007fffefe83fc4 in fftwf_mkplan_d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #12 <https://github.com/gnuradio/gnuradio/pull/12>0x00007fffefe8d95c in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #13 <https://github.com/gnuradio/gnuradio/pull/13>0x00007fffefe8380b in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #14 <https://github.com/gnuradio/gnuradio/pull/14>0x00007fffefe83a03 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #15 <https://github.com/gnuradio/gnuradio/pull/15>0x00007fffefe83fc4 in fftwf_mkplan_d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #16 <https://github.com/gnuradio/gnuradio/pull/16>0x00007fffefe84043 in fftwf_mkplan_f_d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #17 <https://github.com/gnuradio/gnuradio/pull/17>0x00007fffefe887a3 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #18 <https://github.com/gnuradio/gnuradio/pull/18>0x00007fffefe8380b in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #19 <https://github.com/gnuradio/gnuradio/pull/19>0x00007fffefe83a03 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #20 <https://github.com/gnuradio/gnuradio/pull/20>0x00007fffefe83fc4 in fftwf_mkplan_d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #21 <https://github.com/gnuradio/gnuradio/pull/21>0x00007fffefe88e5d in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #22 <https://github.com/gnuradio/gnuradio/pull/22>0x00007fffefe8380b in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #23 <https://github.com/gnuradio/gnuradio/pull/23>0x00007fffefe83a03 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #24 <https://github.com/gnuradio/gnuradio/pull/24>0x00007fffeff4a583 in ?? () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #25 <https://github.com/gnuradio/gnuradio/pull/25>0x00007fffeff4a758 in fftwf_mkapiplan () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #26 <https://github.com/gnuradio/gnuradio/pull/26>0x00007fffeff4ddd7 in fftwf_plan_many_dft () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #27 <https://github.com/gnuradio/gnuradio/pull/27>0x00007fffeff4d09b in fftwf_plan_dft () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #28 <https://github.com/gnuradio/gnuradio/pull/28>0x00007fffeff4cd9a in fftwf_plan_dft_1d () from /lib/x86_64-linux-gnu/libfftw3f.so.3 #29 <https://github.com/gnuradio/gnuradio/pull/29>0x00007fffe99b04d5 in gr::customModule::probeExtract_impl::ApplyFilterBank(int, gr::customModule::probeExtract_impl::FilterBank, std::vector<std::complex, std::allocator<std::complex > >&, int, int, int, std::vector<float, std::allocator >&, int, int, int) ()
from /usr/local/lib/x86_64-linux-gnu/libgnuradio-customModule.so.1.0.0git
#30 <https://github.com/gnuradio/gnuradio/pull/30>0x00007fffe99b1f69 in gr::customModule::probeExtract_impl::general_work(int, std::vector<int, std::allocator >&, std::vector<void const*, std::allocator<void const*> >&, std::vector<void*, std::allocator<void*> >&) () from /usr/local/lib/x86_64-linux-gnu/libgnuradio-customModule.so.1.0.0git #31 <https://github.com/gnuradio/gnuradio/pull/31>0x00007ffff0799c03 in gr::block_executor::run_one_iteration() () from /lib/x86_64-linux-gnu/libgnuradio-runtime.so.3.8.1 #32 <https://github.com/gnuradio/gnuradio/pull/32>0x00007ffff07ed59a in gr::tpb_thread_body::tpb_thread_body(boost::shared_ptrgr::block, boost::shared_ptrboost::barrier, int) ()
from /lib/x86_64-linux-gnu/libgnuradio-runtime.so.3.8.1
#33 <https://github.com/gnuradio/gnuradio/pull/33>0x00007ffff07dd818 in ?? () from /lib/x86_64-linux-gnu/libgnuradio-runtime.so.3.8.1 #34 <https://github.com/gnuradio/gnuradio/pull/34>0x00007ffff07fc4e8 in ?? () from /lib/x86_64-linux-gnu/libgnuradio-runtime.so.3.8.1 #35 <https://github.com/gnuradio/gnuradio/pull/35>0x00007ffff010343b in ?? () from /lib/x86_64-linux-gnu/libboost_thread.so.1.71.0 #36 <https://github.com/gnuradio/gnuradio/issues/36>0x00007ffff7d94609 in start_thread (arg=) at pthread_create.c:477 #37 <https://github.com/gnuradio/gnuradio/pull/37>0x00007ffff7ece133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95




On 2/15/23 13:01, Grace Yeung wrote:
Hi, I have a gnuradio out-of-tree block written in C++ that runs fine in grc 3.8.1.0. But when I have two of them running simultaneously in the flowgraph, grc crashes and gives me the error:

double free or corruption (!prev)

I am not using any free() functions. I use std::vector's in my code which should handle dynamic memory allocation automatically. What could be causing this error?

The only other place I see in the code that deals with pointers is the calling of "new" in the definition of the make function which returns an sptr:
      probeExtract::sptr
      probeExtract::make(const char* filtName, const char* maskName, int mlsrM, int numChan, int sampPerBit, int Tblock, int edgeBufferSize, int structureType)
      {
          return gnuradio::get_initial_sptr
          (new probeExtract_impl(filtName, maskName, mlsrM, numChan, sampPerBit, Tblock, edgeBufferSize, structureType));
      }
I suppose I do not need to worry about free'ing the pointer which is handled internally by python?

After putting in some debugging statements, I see variations of similar error such as:
corrupted size vs. prev_size while consolidating

Any advice would be greatly appreciated. Thank you.

Grace


--
Grace K. Yeung, MS
NorthWest Research Associates
301 Webster Street
Monterey, CA 93940
gr...@nwra.com
https://www.nwra.com

--
Grace K. Yeung, MS
NorthWest Research Associates
301 Webster Street
Monterey, CA 93940
gr...@nwra.com
https://www.nwra.com

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to