Arduino Yun - sketch Memory exceeds limits problem.

hi! I have a memory problem in my Arduino Yun sketch…
The problem occurs in void setup.
i have the code and the log.

When my program checks for the MAC, if MAC is not set yet (no network connection) then it starts setup again.
By using serial monitor I noticed that every time setup runs it uses more and more ram.
The problem occurs only in void setup, and only if there is not network connection while in setup. If there is network it works fine.

What variable do I forget to clear/reset it? Any clues?

Void Setup Code:

#include <Bridge.h>
#include <HttpClient.h>
#include <SoftwareSerial.h>
  #include <EEPROM.h>
#include <Process.h>
 
 
 
//  *** USER DEFINED VARIABLES ***
char likename_def[]="Likes=";   //Important! REPLACE pch+ variables with the likename_def length!!!
char wifidef[]="WiFi Status:";
char like_counter_ver[]="U 10";  // Version 1.0
int debug_mode = 1;
 
 
 
 
char macname_def[]="MAC address:";   //Important! REPLACE pch+ variables with the likename_def length!!!
 
char idbuffer[80];
char uuid_def[]="uuid=";   //Important! REPLACE pch+ variables with the likename_def length!!!
char digitsid[35];
 
char * pchmac;
 
// These are the Arduino pins required to create a software seiral
//  instance. We'll actually only use the TX pin.
const int softwareTx = 4;
const int softwareRx = 2;
 
SoftwareSerial s7s(softwareRx, softwareTx);
 
char tempString[4];  // Will be used with sprintf to create strings
 
 
int digits =0;
char inData[150]; // Allocate some space for the string
char inChar; // Where to store the character read
int index = 0; // Index into array; where to store the character
 
 
 
char * pch;
char * pchid;
char * pchwifi;
char * maczero;
 
void setup() {
 
 Serial.print("SRAM free1 setup: ");
  Serial.println(freeRam());  
 
  char macbuffer[80];
char digitsmac[20];
 
// start reading from the first byte (romdress 0) of the EEPROM
int romdress = 10;
int multiplydress = 11;
byte romval;
byte multiplyval;
 
 
  if (debug_mode==1) {
   
      while (!Serial); // wait for a serial connection
  }
 
  Serial.begin(9600);
  // Start ethernet
  Serial.println(F("Starting ethernet..."));
 
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  // Start bridge
  Serial.println(F("Starting bridge..."));
  Bridge.begin();
  digitalWrite(13, HIGH);
 
  Process wifiCheck;  // initialize a new process
 
  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");  // command you want to run
 
    // while there's any characters coming back from the
  // process, print them to the serial monitor:
  while (wifiCheck.available() > 0) {
    char c2 = wifiCheck.read();
    Serial.print(c2);
    inData[index] = c2; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives
 
      inData[index] = '\0'; // Null terminate the string
   
  }
 
//pchwifi = strstr (inData,wifidef);
 //if (pchwifi != NULL) {
 //  setup();
// }
pchmac = strstr (inData,macname_def);
maczero = strstr (inData, "00:");
  if(pchmac != NULL) {
   // Serial.print("WiFi MAC Result:");
  //Serial.println(pchmac+13);
 //digitsmac = atoi(pchmac+13);
strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));
 
index=0;
  Serial.print("macdata:");
  Serial.println(digitsmac);
 
  if (maczero != NULL) {
      Serial.println("MAC zero!");
    // strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));  
memset(digitsmac, 0, sizeof(digitsmac));  
index=0;
setup();
  } //end if maczero
  }
  else {
     Serial.println("MAC Not Found in string!");
     strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));  
memset(digitsmac, 0, sizeof(digitsmac));  
index=0;
      setup();
  }
 
 
//memset(pchmac, 0, sizeof(pchmac));
//delay(100);
  HttpClient client;
 
  // Make a HTTP request:
   strcpy(macbuffer, "http://mysite.com/bck/ctr/getuuid.php?mac=");
   strcat(macbuffer, digitsmac);
   Serial.print("MAc Buffer:");
   Serial.println(macbuffer);
   client.get(macbuffer);
   
     // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c3 = client.read();
    Serial.print(c3);
    inData[index] = c3; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives
 
      inData[index] = '\0'; // Null terminate the string
 
  }
 
   Serial.print("inDataid:");
  Serial.println(inData);
   pchid = strstr (inData,uuid_def);
  if(pchid != NULL) {
    Serial.print("Search Result uuid:");
  Serial.println(pchid+5);
 //digits = atoi(pchid+6);
strncpy ( digitsid, &pchid[5], 35 );
 memset(inData, 0, sizeof(inData));  
index=0;
// Serial.print("Digitsid:");
 // Serial.println(digitsid);
 
 
//  delay(100);  // This will make the display update at 10Hz.
 
  }
  else {
     Serial.println("Uuid Not Found in string!");
     strncpy ( digitsid, &pchid[5], 35 );
 memset(inData, 0, sizeof(inData));  
 memset(digitsid, 0, sizeof(digitsid));  
index=0;
     setup();
     // Serial.print("Digitsid:");
 // Serial.println(digitsid);
  }
 
 
 
 
 
 
 
    Serial.println(" ");
 
 
 
 
 
 
   // read a byte from the current romdress of the EEPROM
  romval = EEPROM.read(romdress);
   multiplyval = EEPROM.read(multiplydress);
Serial.println("Reading EEPROM...");
Serial.print("EEPROM Address: ");
  Serial.print(romdress);
  Serial.print("\t");
  Serial.print(", Times Powered ON: ");
  Serial.print(romval+multiplyval*255, DEC);
  Serial.println();
// int val2 = analogRead(0) / 4;
 EEPROM.write(romdress, romval+1);
romval = EEPROM.read(romdress);
if (romval>=255) {
 multiplyval++;
romval=0;
 EEPROM.write(romdress, 0);
  EEPROM.write(multiplydress, multiplyval);
 
}
  // Must begin s7s software serial at the correct baud rate.
  //  The default of the s7s is 9600.
  s7s.begin(9600);
 
  clearDisplay();  // Clears display, resets cursor
  setDecimals(0b00000100);  // Sets digit 3 decimal on
 
  s7s.print(like_counter_ver);  // Displays -HI- on all digits
  delay(3000);
  // clearDisplay();  // Clears display, resets cursor
 
  // Clear the display, and then turn on all segments and decimals
  clearDisplay();  // Clears display, resets cursor
  s7s.print("HI  ");  // Displays -HI- on all digits
  delay(1000);
  s7s.print(" 200");
  delay(1000);
   clearDisplay();  // Clears display, resets cursor
  setDecimals(0b111111);  // Turn on all decimals, colon, apos
 
  // Flash brightness values at the beginning
 
  setBrightness(200);  // High brightness
 
 
  // Clear the display before jumping into loop
 
 
 
  delay(2000);
  Serial.println(F("Ready"));
   clearDisplay();  
setDecimals(0b00010000);  // Sets digit 3 decimal on
}

And the log:

Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00
MAC zero!
SRAM free1 setup: 628
Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00
MAC zero!
SRAM free1 setup: 341
Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00B
Ëa¥
MAC zero!
SRAM free1 setup:

Why are all those pointers global? Pointers should almost NEVER be global. A pointer should exist for no longer than the pointed to memory exists.

    inData[index] = c2; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives
 
      inData[index] = '\0'; // Null terminate the string

Doesn’t matter if there’s room, or not, I see. Uh, yes, it does.

Recursively calling setup() from setup() isn’t just a bad idea. It’s stupid.