RasPiArduino icon indicating copy to clipboard operation
RasPiArduino copied to clipboard

Using File variable twice results in error

Open moelski opened this issue 8 years ago • 1 comments
trafficstars

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 avatar Dec 16 '16 17:12 moelski

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

moelski avatar Dec 16 '16 19:12 moelski