Memory leak in libfat

Support for the GBA/DS/Gamecube/Wii media card library
Post Reply
arasium
Posts: 6
Joined: Fri Jan 29, 2010 1:28 pm

Memory leak in libfat

Post by arasium » Fri Jan 29, 2010 1:31 pm

Hi everybody,

i've detected a mamory leak in libfat (perhaps this comes from underlayers).

Here is my code to demonstrate that:

Code: Select all

#include <ogcsys.h>
#include <iostream>
#include <fat.h>
#include <wiiuse/wpad.h>
#include <sdcard/wiisd_io.h>

#include <cstdlib>
#include <unistd.h>

using namespace std;

static void *xfb;
static GXRModeObj *vmode;

void Pause()
{
	while (1)
    {
      // Call WPAD_ScanPads each loop, this reads the latest controller states
      WPAD_ScanPads();

      // WPAD_ButtonsDown tells us which buttons were pressed in this loop
      // this is a "one shot" state which will not fire again until the button has been released
      u32 pressed = WPAD_ButtonsDown(0);

      // We return to the main programme
      if ( pressed & (WPAD_BUTTON_A | WPAD_BUTTON_HOME) )
        break;

      // Wait for the next frame
      VIDEO_WaitVSync();
    }
}

int main(int argc, char **argv)
{
  VIDEO_Init();

  vmode = VIDEO_GetPreferredMode(NULL);
  xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode));

  VIDEO_Configure(vmode);
  VIDEO_SetNextFramebuffer(xfb);
  VIDEO_SetBlack(false);
  VIDEO_Flush();

  VIDEO_WaitVSync();
  if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();

  int x = 20, y = 20, w, h;
  w = vmode->fbWidth - (x * 2);
  h = vmode->xfbHeight - (y + 20);

  // Initialize the console
  CON_InitEx(vmode, x, y, w, h);
  VIDEO_ClearFrameBuffer(vmode, xfb, COLOR_BLACK);	


  u64 pune=0;
  __io_wiisd.startup();
  while(1)
  {
    fatMountSimple("sd",  &__io_wiisd);
    fatUnmount("sd");

    void* blablabla = malloc(256);
    if(!blablabla)break;
    free(blablabla);
    cout << ".";
    pune++;
  }
  __io_wiisd.shutdown();
  cout << endl << "there is no memory left after " << pune << " sd card inits";
  WPAD_Init();
  Pause();
  STM_RebootSystem();
}
Is there any patch to correct this?

arasium
Posts: 6
Joined: Fri Jan 29, 2010 1:28 pm

Re: Memory leak in libfat

Post by arasium » Wed Feb 03, 2010 9:57 am

Please help...

I don't want to use libelm :D Because i've never used it...

Tantric
Posts: 6
Joined: Wed May 20, 2009 10:37 pm

Re: Memory leak in libfat

Post by Tantric » Fri Feb 26, 2010 10:58 pm

Your "memory leak" is caused by incorrect usage of fatUnmount - that line should read fatUnmount("sd:");

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests