mirror of
https://github.com/meshtastic/firmware.git
synced 2026-10-09 22:52:47 -04:00
refactor(net): unique_ptr for connection-lifecycle objects (#11459)
- WiFiServerAPI/ethServerAPI apiPort and ethApiServer's listener are create/destroy cycles that repeat across WiFi teardown and W5500 chip resets; the manual delete+null bookkeeping becomes reset(). (ethTlsApiServer's listener is left for a follow-up: that file is already touched by the partial-init fix PR and converting it here would conflict.) - ContentHandler::handleFormUpload held its body parser raw with delete on four separate exit paths of a per-request handler; any future early return was a silent leak. unique_ptr removes all four. - The portduino ch341Hal global becomes unique_ptr. The LoRa-error recovery loop's delete/null/new sequence was correct only by hand-preserved ordering; it becomes reset()/make_unique. RadioLibHAL keeps a non-owning raw pointer, as before. No behavior change.
This commit is contained in:
1 parent
5e54262fe1
commit
0ff10318ad
8 files changed
+25
-34
No files matched your search
@@ -62,7 +62,7 @@ portduino_config_struct portduino_config;
|
||||
portduino_status_struct portduino_status;
|
||||
std::ofstream traceFile;
|
||||
std::ofstream JSONFile;
|
||||
Ch341Hal *ch341Hal = nullptr;
|
||||
std::unique_ptr<Ch341Hal> ch341Hal;
|
||||
char *configPath = nullptr;
|
||||
char *optionMac = nullptr;
|
||||
bool verboseEnabled = false;
|
||||
@@ -325,8 +325,8 @@ void portduinoSetup()
|
||||
{
|
||||
extern void wasm_config_apply();
|
||||
wasm_config_apply();
|
||||
ch341Hal =
|
||||
new Ch341Hal(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid, portduino_config.lora_usb_pid);
|
||||
ch341Hal = std::make_unique<Ch341Hal>(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid,
|
||||
portduino_config.lora_usb_pid);
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
@@ -650,8 +650,8 @@ void portduinoSetup()
|
||||
uint8_t dmac[6] = {0};
|
||||
if (portduino_config.lora_spi_dev == "ch341") {
|
||||
try {
|
||||
ch341Hal = new Ch341Hal(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid,
|
||||
portduino_config.lora_usb_pid);
|
||||
ch341Hal = std::make_unique<Ch341Hal>(0, portduino_config.lora_usb_serial_num, portduino_config.lora_usb_vid,
|
||||
portduino_config.lora_usb_pid);
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << "Could not initialize CH341 device!" << std::endl;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unistd.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
@@ -64,7 +65,7 @@ struct pinMapping {
|
||||
extern std::ofstream traceFile;
|
||||
extern std::ofstream JSONFile;
|
||||
|
||||
extern Ch341Hal *ch341Hal;
|
||||
extern std::unique_ptr<Ch341Hal> ch341Hal;
|
||||
int initGPIOPin(int pinNum, const std::string &gpioChipname, int line);
|
||||
bool loadConfig(const char *configPath);
|
||||
static bool ends_with(std::string_view str, std::string_view suffix);
|
||||
|
||||
Reference in new issue
Block a user