Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson committed Aug 27, 2023
1 parent bac6da5 commit 3c552f1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"string": "c",
"string_view": "c"
},
"editor.formatOnSave": true
"editor.formatOnSave": true,
"cSpell.words": [
"ssid"
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewChecked, Component, ElementRef, ViewChild } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { Observable } from 'rxjs';
import { interval, Observable, switchMap } from 'rxjs';
import { LoadingService } from 'src/app/services/loading.service';
import { SystemService } from 'src/app/services/system.service';
import { WebsocketService } from 'src/app/services/web-socket.service';
Expand All @@ -23,8 +23,11 @@ export class HomeComponent implements AfterViewChecked {
private loadingService: LoadingService,
private websocketService: WebsocketService
) {
this.info$ = this.systemService.getInfo().pipe(
this.loadingService.lockUIUntilComplete()

this.info$ = interval(3000).pipe(
switchMap(() => {
return this.systemService.getInfo()
})
)

this.websocketService.ws$.subscribe({
Expand Down
20 changes: 15 additions & 5 deletions main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ static esp_err_t GET_system_info(httpd_req_t *req)
httpd_resp_set_hdr(req, "Access-Control-Allow-Headers", "Content-Type");
httpd_resp_set_hdr(req, "Access-Control-Allow-Credentials", "true");

char *ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, CONFIG_ESP_WIFI_SSID);
char *wifiPass = nvs_config_get_string(NVS_CONFIG_WIFI_PASS, CONFIG_ESP_WIFI_PASSWORD);
char *stratumURL = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL);
char *stratumUser = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);

cJSON *root = cJSON_CreateObject();
cJSON_AddNumberToObject(root, "power", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.power);
cJSON_AddNumberToObject(root, "voltage", GLOBAL_STATE->POWER_MANAGEMENT_MODULE.voltage);
Expand All @@ -265,20 +270,25 @@ static esp_err_t GET_system_info(httpd_req_t *req)
cJSON_AddStringToObject(root, "bestDiff", GLOBAL_STATE->SYSTEM_MODULE.best_diff_string);
cJSON_AddNumberToObject(root, "freeHeap", esp_get_free_heap_size());
cJSON_AddNumberToObject(root, "coreVoltage", ADC_get_vcore());
cJSON_AddStringToObject(root, "ssid", nvs_config_get_string(NVS_CONFIG_WIFI_SSID, CONFIG_ESP_WIFI_SSID));
cJSON_AddStringToObject(root, "wifiPass", nvs_config_get_string(NVS_CONFIG_WIFI_PASS, CONFIG_ESP_WIFI_PASSWORD));
cJSON_AddStringToObject(root, "ssid", ssid);
cJSON_AddStringToObject(root, "wifiPass", wifiPass);
cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status);
cJSON_AddNumberToObject(root, "sharesAccepted", GLOBAL_STATE->SYSTEM_MODULE.shares_accepted);
cJSON_AddNumberToObject(root, "sharesRejected", GLOBAL_STATE->SYSTEM_MODULE.shares_rejected);
cJSON_AddNumberToObject(root, "uptimeSeconds", (esp_timer_get_time() - GLOBAL_STATE->SYSTEM_MODULE.start_time) / 1000000);
cJSON_AddStringToObject(root, "ASICModel", CONFIG_ASIC_MODEL);
cJSON_AddStringToObject(root, "stratumURL", nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL));
cJSON_AddStringToObject(root, "stratumURL", stratumURL);
cJSON_AddNumberToObject(root, "stratumPort", nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT));
cJSON_AddStringToObject(root, "stratumUser", nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER));
cJSON_AddStringToObject(root, "stratumUser", stratumUser);

free(ssid);
free(wifiPass);
free(stratumURL);
free(stratumUser);

const char *sys_info = cJSON_Print(root);
httpd_resp_sendstr(req, sys_info);
free((void *)sys_info);
free(sys_info);
cJSON_Delete(root);
return ESP_OK;
}
Expand Down
1 change: 1 addition & 0 deletions main/nvs_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ char *nvs_config_get_string(const char *key, const char *default_value)
if (err != ESP_OK)
{
ESP_LOGW(TAG, "Key %s not found in nvs, using default value", key);
free(out);
return strdup(default_value);
}

Expand Down

0 comments on commit 3c552f1

Please sign in to comment.