Csound Csound-dev Csound-tekno Search About

[Cs-dev] freeing invalid pointer

Date2011-05-22 13:33
Fromebmtranceboy
Subject[Cs-dev] freeing invalid pointer
Hi,

I'm on ubuntu (Csound version 5.10 Double) and I have a
*** glibc detected *** csound: free(): invalid pointer: 0x08a25b78 ***

when I test my pvsfocus plugin (a simple opcode that resets the amplitudes
of an fsig if the corresponding frequencies does not fit a given frame
[lowfreq,highfreq]) which sounds the way I expected despite that:

#include "csdl.h"
#include "pstream.h"

typedef struct {
    OPDS h;
    PVSDAT *fout;
    PVSDAT *fin;
    MYFLT  *klow;
    MYFLT  *khigh;
    MYFLT  lastframe;
 } PVSFOCUS;

static int pvsfocusinit(CSOUND *csound, PVSFOCUS *p){
    int     N = p->fin->N;

    if (p->fout->frame.auxp == NULL || p->fout->frame.size <
(N+2)*sizeof(float))  /* RWD MUST be 32bit */
            csound->AuxAlloc(csound, (N+2)*sizeof(float), &p->fout->frame);
	    else memset(p->fout->frame.auxp, 0, (N+2)*sizeof(MYFLT));

    p->fout->N = N;
    p->fout->overlap = p->fin->overlap;
    p->fout->winsize = p->fin->winsize;
    p->fout->wintype = p->fin->wintype;
    p->fout->format = p->fin->format;
    p->fout->framecount = 1;
    p->lastframe=0;
    return OK;
}

static int pvsfocus(CSOUND *csound, PVSFOCUS *p){
    int     i, N = p->fin->N;
    float   *fin = (float *) p->fin->frame.auxp;
    float   *fout = (float *) p->fout->frame.auxp;
    MYFLT low = *p->klow;
    MYFLT high = *p-> khigh;

    if (p->lastframe < p->fin->framecount) {
      for (i = 0; i < N; i += 2) {
        MYFLT frq = fin[i+1];
        MYFLT afrq = (frq<FL(0.0)? -frq : frq);
        fout[i+1] = frq;
        if (afrq < low || afrq>high)
            fout[i] = FL(0.0);
          else 
            fout[i] = fin[i];
      }
      p->fout->framecount = p->lastframe = p->fin->framecount;
    }
    return OK;
}

static OENTRY localops[] = {
  {"pvsfocus", sizeof(PVSFOCUS), 3, "f", "fkk", (SUBR) pvsfocusinit, (SUBR)
pvsfocus, (SUBR) NULL }
 };

LINKAGE



Here is my test.csd:



-d -odac


sr        =         44100
kr        =         100
nchnls    =         1
0dbfs     =      1

instr     1
  a0 rand 1
  ifftsize = 2048
  f0  pvsanal a0, ifftsize, ifftsize/4, ifftsize, 0
  imin = p4
  imax = p5
  i0 = (imin+imax)/2
  idelta = 10
  kosc oscil 1, 3,1
  klow = (i0-idelta-imin)*(1+kosc)/2+imin
  khigh = (imax - i0 - idelta)*(1+kosc)/2+i0+idelta
  f1 pvsfocus  f0 ,klow, khigh
  asig pvsynth f1
  out      asig
endin




f1 0 4096 10 1

i1 0 1 50 8000
i1 + 1 60 5000
i1 + 1 70 4000
i1 + 1 80 3000
i1 + 1 90 2000
i1 + 1 100 1500
i1 + 1 120 1200
i1 + 1 150 1000
i1 + 1 180 800
i1 + 1 200 500
i1 + 1 300 400
i1 + 1 30 400




Can you please help me?



--
View this message in context: http://csound.1045644.n5.nabble.com/freeing-invalid-pointer-tp4416648p4416648.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2011-05-22 13:42
Fromjpff@cs.bath.ac.uk
SubjectRe: [Cs-dev] freeing invalid pointer
Note that the originl sender is not on the develop list, so please copy
him in on any response

==John ff (dministrator)


> Hi,
>
> I'm on ubuntu (Csound version 5.10 Double) and I have a
> *** glibc detected *** csound: free(): invalid pointer: 0x08a25b78 ***
>
> when I test my pvsfocus plugin (a simple opcode that resets the amplitudes
> of an fsig if the corresponding frequencies does not fit a given frame
> [lowfreq,highfreq]) which sounds the way I expected despite that:
>
> #include "csdl.h"
> #include "pstream.h"
>
> typedef struct {
>     OPDS h;
>     PVSDAT *fout;
>     PVSDAT *fin;
>     MYFLT  *klow;
>     MYFLT  *khigh;
>     MYFLT  lastframe;
>  } PVSFOCUS;
>
> static int pvsfocusinit(CSOUND *csound, PVSFOCUS *p){
>     int     N = p->fin->N;
>
>     if (p->fout->frame.auxp == NULL || p->fout->frame.size <
> (N+2)*sizeof(float))  /* RWD MUST be 32bit */
>             csound->AuxAlloc(csound, (N+2)*sizeof(float),
> &p->fout->frame);
> 	    else memset(p->fout->frame.auxp, 0, (N+2)*sizeof(MYFLT));
>
>     p->fout->N = N;
>     p->fout->overlap = p->fin->overlap;
>     p->fout->winsize = p->fin->winsize;
>     p->fout->wintype = p->fin->wintype;
>     p->fout->format = p->fin->format;
>     p->fout->framecount = 1;
>     p->lastframe=0;
>     return OK;
> }
>
> static int pvsfocus(CSOUND *csound, PVSFOCUS *p){
>     int     i, N = p->fin->N;
>     float   *fin = (float *) p->fin->frame.auxp;
>     float   *fout = (float *) p->fout->frame.auxp;
>     MYFLT low = *p->klow;
>     MYFLT high = *p-> khigh;
>
>     if (p->lastframe < p->fin->framecount) {
>       for (i = 0; i < N; i += 2) {
>         MYFLT frq = fin[i+1];
>         MYFLT afrq = (frq<FL(0.0)? -frq : frq);
>         fout[i+1] = frq;
>         if (afrq < low || afrq>high)
>             fout[i] = FL(0.0);
>           else
>             fout[i] = fin[i];
>       }
>       p->fout->framecount = p->lastframe = p->fin->framecount;
>     }
>     return OK;
> }
>
> static OENTRY localops[] = {
>   {"pvsfocus", sizeof(PVSFOCUS), 3, "f", "fkk", (SUBR) pvsfocusinit,
> (SUBR)
> pvsfocus, (SUBR) NULL }
>  };
>
> LINKAGE
>
>
>
> Here is my test.csd:
>
> 
> 
> -d -odac
> 
> 
> sr        =         44100
> kr        =         100
> nchnls    =         1
> 0dbfs     =      1
>
> instr     1
>   a0 rand 1
>   ifftsize = 2048
>   f0  pvsanal a0, ifftsize, ifftsize/4, ifftsize, 0
>   imin = p4
>   imax = p5
>   i0 = (imin+imax)/2
>   idelta = 10
>   kosc oscil 1, 3,1
>   klow = (i0-idelta-imin)*(1+kosc)/2+imin
>   khigh = (imax - i0 - idelta)*(1+kosc)/2+i0+idelta
>   f1 pvsfocus  f0 ,klow, khigh
>   asig pvsynth f1
>   out      asig
> endin
>
> 
> 
>
> f1 0 4096 10 1
>
> i1 0 1 50 8000
> i1 + 1 60 5000
> i1 + 1 70 4000
> i1 + 1 80 3000
> i1 + 1 90 2000
> i1 + 1 100 1500
> i1 + 1 120 1200
> i1 + 1 150 1000
> i1 + 1 180 800
> i1 + 1 200 500
> i1 + 1 300 400
> i1 + 1 30 400
>
> 
> 
>
> Can you please help me?
>
>
>
> --
> View this message in context:
> http://csound.1045644.n5.nabble.com/freeing-invalid-pointer-tp4416648p4416648.html
> Sent from the Csound - Dev mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> What Every C/C++ and Fortran developer Should Know!
> Read this article and learn how Intel has extended the reach of its
> next-generation tools to help Windows* and Linux* C/C++ and Fortran
> developers boost performance applications - including clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
>



------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2011-05-22 13:43
Fromebmtranceboy
SubjectRe: [Cs-dev] freeing invalid pointer
it works when commenting the
    else memset(p->fout->frame.auxp, 0, (N+2)*sizeof(MYFLT)); 
line !

sorry for the noise

--
View this message in context: http://csound.1045644.n5.nabble.com/freeing-invalid-pointer-tp4416648p4416670.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net