Author Topic: resbuf leaks  (Read 3028 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7012
  • AKA Daniel
resbuf leaks
« on: July 13, 2010, 10:44:04 AM »
Why does lfunc2  leak and lfunc1 not leak?

Code: [Select]
static int ads_lfunc1(void)
  {
    resbuf *phead = acutNewRb(RTLB);
    resbuf *pTail = phead;
    for(size_t idx = 0;idx < 5000;idx++)
    {
      pTail = pTail->rbnext = acutNewRb(RTLB);
      pTail = pTail->rbnext = acutNewRb(RTSTR);
      pTail->resval.rstring = _T("Hello");
      pTail = pTail->rbnext = acutNewRb(RTDOTE);
      pTail = pTail->rbnext = acutNewRb(RTSTR);
      pTail->resval.rstring = _T("world");
      pTail = pTail->rbnext = acutNewRb(RTLE);
    }
    pTail = pTail->rbnext = acutNewRb(RTLE);
    acutRelRb(phead);
    return (RSRSLT) ;
  }

  static int ads_lfunc2(void)
  {
    resbuf *phead = acutNewRb(RTLB);
    resbuf *pTail = phead;
    for(size_t idx = 0;idx < 5000;idx++)
    {
      pTail = pTail->rbnext =
        acutBuildList(RTLB,RTSTR,_T("HELLO"),RTDOTE,RTSTR,_T("world"),RTLE,0);
    }
    pTail = pTail->rbnext = acutNewRb(RTLE);
    acutRelRb(phead);
    return (RSRSLT) ;
  }
« Last Edit: July 13, 2010, 10:52:34 AM by Daniel »

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7012
  • AKA Daniel
Re: resbuf leaks
« Reply #1 on: July 13, 2010, 11:08:03 AM »
(repeat 200 (lfunc2))

before & after

pkohut

  • Guest
Re: resbuf leaks
« Reply #2 on: July 13, 2010, 11:23:54 AM »
Logic error
pTail = pTail->rbnext = acutBuildList...


edit: Don't know, the code looks fine through these blurry eyes.
« Last Edit: July 13, 2010, 11:33:41 AM by pkohut »

pkohut

  • Guest
Re: resbuf leaks
« Reply #3 on: July 13, 2010, 11:47:25 AM »
Logic error
pTail = pTail->rbnext = acutBuildList...


edit: Don't know, the code looks fine through these blurry eyes.

Take that back. Logic error
Code: [Select]
pTail = pTail->rbnext = acutBuildList...is the correct answer.

Need a hint? How many list items is acutBuildList returning? Where are you sticking pTail to?

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7012
  • AKA Daniel
Re: resbuf leaks
« Reply #4 on: July 13, 2010, 11:53:36 AM »
yep I see it

Code: [Select]
static resbuf*  RbTail( const resbuf* src )
  {
    if (src != 0)
    {
      resbuf *pItr = const_cast<resbuf*>(src);
      while (pItr->rbnext != NULL)
        pItr = pItr->rbnext;
      return pItr;
    }
    return 0;
  }

  static int ads_lfunc2(void)
  {
    resbuf *phead = acutNewRb(RTLB);
    resbuf *pTail = phead;
    for(size_t idx = 0;idx < 5000;idx++)
    {
      pTail = pTail->rbnext = acutBuildList(RTLB,RTSTR,_T("HELLO"),RTDOTE,RTSTR,_T("world"),RTLE,0);
      pTail = RbTail(pTail);
    }
    pTail = pTail->rbnext = acutNewRb(RTLE);
    acutRelRb(phead);
    return (RSRSLT) ;
  }

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 7012
  • AKA Daniel
Re: resbuf leaks
« Reply #5 on: July 13, 2010, 11:54:37 AM »
Thanks Paul  8-)