me-no-dev / RasPiArduino

Arduino Framework for RaspberryPI
326 stars 76 forks source link

Using File variable twice results in error #59

Open moelski opened 7 years ago

moelski commented 7 years ago

Hi !

Maybe I´m doing something wrong but this code did not work:

  File script = FileSystem.open("wlan-stats.sh", FILE_WRITE);
  script.print("#!/bin/sh\n");
  script.print("ifconfig wlan0 | grep 'RX bytes'\n");
  script.close();  // close the file

  script = FileSystem.open("wlan-stats2.sh", FILE_WRITE);
  script.print("#!/bin/sh\n");
  script.print("ifconfig wlan0 | grep 'RX bytes'\n");
  script.close();  // close the file

It results in this error:

Error in `./FileWriteScript.ino.bplus.bin': double free or corruption (out): 0xb6300480

Any idea what´s going wrong here ?

Dominik

moelski commented 7 years ago

Hi !

I think this is related to the destructor... With this code it works:

File::~File() {
  //close();
}

I think there is some handling missing if the file was closed before or not. Maybe you can add some control structure for that?

Dominik