Fix leak in arduino lua

This commit is contained in:
Paul Dino Jones 2025-03-26 12:35:16 -04:00
parent d1f43aace5
commit e2b5e4b5d1
2 changed files with 11 additions and 7 deletions

View File

@ -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 */ /* If something went wrong, error message is at the top of */
/* the stack */ /* the stack */
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1)); fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
lua_close(serialdevice->m.L);
return -1;
exit(1); exit(1);
} }
lua_setglobal(L,"myFunc"); lua_setglobal(L,"myFunc");
@ -328,13 +330,9 @@ int arduino_customled_free(SerialDevice* serialdevice, bool lua)
} }
size_t size = sizeof(bytes); 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); int result = monocoque_serial_write_block(serialdevice->id, &bytes, size, arduino_timeout);
if(lua == true)
{
lua_close(serialdevice->m.L); lua_close(serialdevice->m.L);
}
return result; return result;
} }

View File

@ -174,6 +174,7 @@ int serialdev_free(SimDevice* this)
break; break;
case ARDUINODEV__SIMLED__CUSTOM: case ARDUINODEV__SIMLED__CUSTOM:
arduino_customled_free(serialdevice, true); arduino_customled_free(serialdevice, true);
free(serialdevice->m.device_specific_config_file);
break; break;
case ARDUINODEV__SIMLED: case ARDUINODEV__SIMLED:
arduino_customled_free(serialdevice, false); arduino_customled_free(serialdevice, false);
@ -217,7 +218,12 @@ int serialdev_init(SerialDevice* serialdevice, DeviceSettings* ds)
error = moza_init(serialdevice, ds->serialdevsettings.portdev); error = moza_init(serialdevice, ds->serialdevsettings.portdev);
break; break;
case ARDUINODEV__SIMLED__CUSTOM: 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; break;
case ARDUINODEV__SIMLED: case ARDUINODEV__SIMLED:
error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL); error = arduino_customled_init(serialdevice, ds->serialdevsettings.portdev, NULL);