Fix leak in arduino lua
This commit is contained in:
parent
d1f43aace5
commit
e2b5e4b5d1
|
|
@ -115,6 +115,8 @@ int arduino_customled_init(SerialDevice* serialdevice, const char* portdev, cons
|
|||
/* If something went wrong, error message is at the top of */
|
||||
/* the stack */
|
||||
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
|
||||
lua_close(serialdevice->m.L);
|
||||
return -1;
|
||||
exit(1);
|
||||
}
|
||||
lua_setglobal(L,"myFunc");
|
||||
|
|
@ -328,13 +330,9 @@ int arduino_customled_free(SerialDevice* serialdevice, bool lua)
|
|||
}
|
||||
size_t size = sizeof(bytes);
|
||||
|
||||
// temporary hack to help it shut off
|
||||
sleep(1);
|
||||
int result = monocoque_serial_write_block(serialdevice->id, &bytes, size, arduino_timeout);
|
||||
|
||||
if(lua == true)
|
||||
{
|
||||
lua_close(serialdevice->m.L);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ int serialdev_free(SimDevice* this)
|
|||
break;
|
||||
case ARDUINODEV__SIMLED__CUSTOM:
|
||||
arduino_customled_free(serialdevice, true);
|
||||
free(serialdevice->m.device_specific_config_file);
|
||||
break;
|
||||
case ARDUINODEV__SIMLED:
|
||||
arduino_customled_free(serialdevice, false);
|
||||
|
|
@ -217,7 +218,12 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
|
|||
error = moza_init(serialdevice, ds->serialdevsettings.portdev);
|
||||
break;
|
||||
case ARDUINODEV__SIMLED__CUSTOM:
|
||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, ds->specific_config_file);
|
||||
serialdevice->m.device_specific_config_file = strdup(ds->specific_config_file);
|
||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, serialdevice->m.device_specific_config_file);
|
||||
if(error < 0)
|
||||
{
|
||||
free(serialdevice->m.device_specific_config_file);
|
||||
}
|
||||
break;
|
||||
case ARDUINODEV__SIMLED:
|
||||
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL);
|
||||
|
|
|
|||
Loading…
Reference in New Issue