Running out of memory for (seemingly) no reason!

Here's my code. For some reason I'm running out of code. Please take a gander. Thanks!

#include <SoftwareSerial.h>

#include <SD.h>

SoftwareSerial mySerial(2, 4);

int resetpin = 3;  //Reader reset pin.
int ledpin = 7;  //Status LED pin.
int CS_pin = 10;

void setup() {

  Serial.begin(9600);  //Initialize main serial connection.
  mySerial.begin(9600);  //Initialize reader serial connection.
  pinMode(resetpin, OUTPUT);  //Define reset pin as an output.
  pinMode(ledpin, OUTPUT);  //Define the LED pin as output.
  pinMode(CS_pin, OUTPUT);
  digitalWrite(resetpin, HIGH);  //Pull the reset pin high.
  Serial.println("Initializing SD Card");

  if (!SD.begin(CS_pin)) {
    Serial.println("Card Failed. Quitting");
    return;
  }

  Serial.println("SD Card Ready");
  Serial.println("Waiting for Tag");
}

void loop() {

  char readByte, tempByte, addByte[13], tagString[13], mastertag[13] = {
    '4', 'E', '0', '0', '0', '4', '3', 'D', '3', '8', '4', 'F'        };
  int index = 0, filesize;
  boolean reading = false, cardreading = false, cardready = false;
  File logread = SD.open("log.txt", FILE_WRITE);

  while (mySerial.available() > 0) {

    readByte = mySerial.read();

    if(readByte == 2) reading = true;
    if(readByte == 3) reading = false;

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){
      tagString[index] = readByte;
      index ++;
    }
  }

  printtag(tagString);

  if (strlen(tagString) != 0) {
    if (database(tagString) == true) {
      Serial.println("Match Found");
      digitalWrite(ledpin, HIGH);
      delay(1000);
      digitalWrite(ledpin, LOW);
    }
    else {

      Serial.println("No Match Found");
    }

  }

  if (compare(mastertag, tagString)) {
    Serial.println("Master Tag Found, Entering Admin Mode");
    resetreader();
    index = 0;
    delay(3000);

    while (cardready == false) {
        while (mySerial.available() > 0) {
          tempByte = mySerial.read();

          if (tempByte == 2) cardreading = true;
          if (tempByte == 3) cardreading = false;

          if (cardreading && tempByte != 2 && tempByte != 10 && tempByte != 13) {
            addByte[index] = tempByte;
            index ++;
          }
        }
        if (index == 12) {
          Serial.println("Done Reading");
          filesize = logread.size();
          logread.seek(filesize);
          logread.print(addByte[0]);
          logread.print(addByte[1]);
          logread.print(addByte[2]);
          logread.print(addByte[3]);
          logread.print(addByte[4]);
          logread.print(addByte[5]);
          logread.print(addByte[6]);
          logread.print(addByte[7]);
          logread.print(addByte[8]);
          logread.print(addByte[9]);
          logread.print(addByte[10]);
          logread.print(addByte[11]);
          logread.close();
          cardready = true;
        }
    }
  }
  cleartag(tagString);
  resetreader();
  delay(200);
}

void resetreader() {
  digitalWrite(resetpin, LOW);
  digitalWrite(resetpin, HIGH);
  delay(150);
}

boolean compare(char one[], char two[]) {

  for (int i = 0; i < 12; i++) {
    if (one[i] != two[i]) {
      return false;
    }
  }
  return true;
}

void cleartag(char one[]) {

  for (int i = 0; i < strlen(one); i++) {
    one[i] = 0;
  }
}

void printtag(char one[]) {

  int printer = 0;

  if (!strlen(one) == 0) {

    for (int i = 0; i < 12; i++) {
      Serial.print(one[i]);
      printer++;
    }
    if (printer == 12) {
      Serial.println();
    }
  }
}

boolean database(char one[]) {

  char sdarray[13];
  boolean match = false;
  File logread = SD.open("log.txt", FILE_WRITE);

if (logread) {
    logread.seek(0);
    while (logread.available() && match == false) {
      for (int i = 0; i < 12; i++) {
        sdarray[i] = logread.read();
      }

      if (compare(one, sdarray) && match == false) {
        match = true;
        logread.close();
        return true;
      }
    }

    if (match == false && !logread.available()) {
      logread.close();
      return false;
    }
  }
}

Moderator edit: Thread locked. Don't just start a new topic when you asked the same question in another thread. Thanks. (Nick Gammon)

http://arduino.cc/forum/index.php/topic,100364