releasing memory in sub-function I'm doing a program who get a line from the SD and shows it, this function is called getData()

FULL CODE:

#include &lt;SD.h&gt;
#include &lt;MemoryFree.h&gt;

File myFile;
int stringIndex = 0;
int cursorPosition = 0;
char inputString [25];
char inputChar;
boolean endOfLine;
char fullPath[11];

void setup(){

  Serial.begin(9600);

  Serial.print("Initializing SD card.");
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

}

void loop(){

  Serial.println(getDataSD());

  Serial.print("freeMemory()=");
  Serial.println(freeMemory());
}

String getDataSD(){

  memset(inputString, 0, sizeof(inputString));

  getFileNameSD();

  myFile = SD.open(fullPath);

  if(myFile){
    myFile.seek(cursorPosition);

    endOfLine = false;    

    while(myFile.available() &amp;&amp; endOfLine == false){
      inputChar = myFile.read();

      if(inputChar == '*'){
        while(inputChar != '\n'){
          inputChar = myFile.read();
        }
      }else{
        cursorPosition = myFile.position()-1;

        if(inputChar == 10 || inputChar == ' ') inputChar = myFile.read();

        while(inputChar != '\n'){
          if(stringIndex &lt; 25){          
            inputString[stringIndex] = inputChar;
            stringIndex++;
            inputChar = myFile.read();
          }
        }
        inputString[stringIndex-1] = '\0';        
        stringIndex    = 0;
        endOfLine      = true;        
      }      
    }
    myFile.close();    
  }
  return inputString;
}

void getFileNameSD (){

  char folder[] = "/ACC";

  checkFolderSD(folder);  

  myFile = SD.open(folder);
  myFile = myFile.openNextFile();

  if(!myFile) myFile.rewindDirectory();

  if(myFile){

    strcpy(fullPath,folder);
    strcat(fullPath,"/");
    strcat(fullPath,myFile.name());

    myFile.close();
  }
}


I don't have problem with this function(getDataSD). To get the name of the file, I've created another function who looks for a file in a specific folder, this function is called getFileNameSD()

I'm having problem with this last function, it's not releasing or overwriting some data, so every time it's called, it is stored new data in memory

I've included the memory Free library to see where is the problem. When I call the getDataSD and write the file manually I dont have problem.

myFile = SD.open("/ACC/11001");


Serial monitor

freeMemory()=6592
/-27/-26/-56/
freeMemory()=6592
/-27/-26/-56/
freeMemory()=6592
/-27/-26/-56/
freeMemory()=6592
/-27/-26/-56/
freeMemory()=6592
/-27/-26/-56/
freeMemory()=6592
/-27/-26/-56/


the memory always is the same.

but not when I call the getFileNameSD() 

myFile = SD.open(getFileNameSD());


Serial monitor

freeMemory()=6571
/-27/-26/-56/
freeMemory()=6540
/-27/-26/-56/
freeMemory()=6509
/-27/-26/-56/
freeMemory()=6478
/-27/-26/-56/
freeMemory()=6447
/-27/-26/-56/


I know I'm doing something wrong with getFileName() but I don't know what is, can anybody help/explain me?
Ok,

I don't know, why your memory is leaking, but anyway, your program won't work safely. 
You defined an array (fullPath) inside the local scope of your function. You return it, which means, you return a pointer to this array. But at the same time, this array gets invalid, because you leave the local scope of your function.

Better define that string outside the function and give it as a parameter to the function. Then you aren't in danger of accessing an invalid pointer. Furthermore your memory leak won't appear.