Skip to content

Commit cceb288

Browse files
committed
v3.37
1 parent 0011dfc commit cceb288

File tree

4 files changed

+43
-19
lines changed

4 files changed

+43
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ or to show the help page
160160
If everything works properly, you will see something like this:
161161

162162
```
163-
rscp2mqtt [3.36]
163+
rscp2mqtt [3.37]
164164
E3DC system >192.168.178.111:5033< user: >your E3DC user<
165165
MQTT broker >localhost:1883< qos = >0< retain = >✗< tls >✗< client id >✗< prefix >e3dc<
166166
Requesting PVI ✓ | PM (0) | DCB ✓ (1 battery string) | Wallbox ✗ | Interval 2 | Autorefresh ✓ | Raw data ✗ | Logging OFF

RELEASE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## Release Notes
22

3+
### Release v3.37 (12.04.2025)
4+
5+
Bug fixes:
6+
- Issue #106: Unexpected program crash when using raw mode
7+
- Issue #107: Memory leak in v3.36
8+
39
### Release v3.36 (29.03.2025)
410

511
Features:

RscpMqttMain.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <regex>
2323
#include <mutex>
2424

25-
#define RSCP2MQTT_VERSION "3.36"
25+
#define RSCP2MQTT_VERSION "3.37"
2626

2727
#define AES_KEY_SIZE 32
2828
#define AES_BLOCK_SIZE 32
@@ -126,7 +126,13 @@ char *tagName(std::vector<RSCP_TAGS::tag_overview_t> & v, uint32_t tag) {
126126
return(it->name);
127127
}
128128
}
129-
return(NULL);
129+
char name[128];
130+
sprintf(name, "0x%02X", tag);
131+
RSCP_TAGS::tag_overview_t tag_overview = { tag, "", 0 };
132+
strcpy(tag_overview.name, name);
133+
RSCP_TAGS::RscpTagsOverview.push_back(tag_overview);
134+
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"tagName: new tag >%s<\n", name);
135+
return(tagName(v, tag));
130136
}
131137

132138
uint32_t tagID(std::vector<RSCP_TAGS::tag_overview_t> & v, char *name) {
@@ -148,12 +154,14 @@ bool isTag(std::vector<RSCP_TAGS::tag_overview_t> & v, char *name, bool must_be_
148154
}
149155

150156
char *typeName(std::vector<RSCP_TAGS::rscp_types_t> & v, uint8_t code) {
157+
char *unknown = NULL;
151158
for (std::vector<RSCP_TAGS::rscp_types_t>::iterator it = v.begin(); it != v.end(); ++it) {
159+
if (!it->code) unknown = it->type;
152160
if (it->code == code) {
153161
return(it->type);
154162
}
155163
}
156-
return(NULL);
164+
return(unknown);
157165
}
158166

159167
uint8_t typeID(std::vector<RSCP_TAGS::rscp_types_t> & v, char *type) {
@@ -870,7 +878,7 @@ int mergeRawData(char *topic, char *payload, bool *changed) {
870878
if (!strcmp(it->topic, topic) && !it->handled && (i == it->nr)) {
871879
if (strcmp(it->payload, payload)) {
872880
if (strlen(it->payload) != strlen(payload)) it->payload = (char *)realloc(it->payload, strlen(payload) + 1);
873-
strcpy(it->payload, payload);
881+
if (it->payload) strcpy(it->payload, payload);
874882
it->changed = true;
875883
*changed = true;
876884
}
@@ -2125,18 +2133,20 @@ void publishRaw(RscpProtocol *protocol, SRscpValue *response, char *topic_in) {
21252133
char topic[TOPIC_SIZE];
21262134
char *payload = (char *)malloc(PAYLOAD_SIZE * sizeof(char) + 1);
21272135
bool changed = false;
2128-
memset(payload, 0, PAYLOAD_SIZE);
2129-
preparePayload(protocol, response, &payload);
2136+
if (payload) {
2137+
memset(payload, 0, PAYLOAD_SIZE);
2138+
preparePayload(protocol, response, &payload);
21302139

2131-
int nr = mergeRawData(topic_in, payload, &changed);
2132-
if (nr > 0) {
2133-
if (snprintf(topic, TOPIC_SIZE, "%s/%d", topic_in, nr) >= TOPIC_SIZE) {
2134-
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"publishRaw: Buffer overflow\n");
2135-
return;
2136-
}
2137-
if (changed) publishImmediately(topic, payload, false);
2138-
} else if (changed) publishImmediately(topic_in, payload, false);
2139-
if (payload) free(payload);
2140+
int nr = mergeRawData(topic_in, payload, &changed);
2141+
if (nr > 0) {
2142+
if (snprintf(topic, TOPIC_SIZE, "%s/%d", topic_in, nr) >= TOPIC_SIZE) {
2143+
logMessage(cfg.logfile, (char *)__FILE__, __LINE__, (char *)"publishRaw: Buffer overflow\n");
2144+
return;
2145+
}
2146+
if (changed) publishImmediately(topic, payload, false);
2147+
} else if (changed) publishImmediately(topic_in, payload, false);
2148+
free(payload);
2149+
}
21402150
return;
21412151
}
21422152

@@ -2325,6 +2335,7 @@ int handleResponseValue(RscpProtocol *protocol, SRscpValue *response) {
23252335
if (storeResponseValue(RSCP_MQTT::RscpMqttCache, protocol, &(subcontainer[k]), containerData[i].tag, dcb_nr) < 0) break;
23262336
}
23272337
}
2338+
protocol->destroyValueData(subcontainer); // Issue #107
23282339
}
23292340
}
23302341
}
@@ -3614,6 +3625,11 @@ int main(int argc, char *argv[]) {
36143625
logMessageCache(cfg.logfile, false);
36153626
}
36163627

3628+
for (std::vector<RSCP_MQTT::raw_data_t>::iterator it = RSCP_MQTT::rawData.begin(); it != RSCP_MQTT::rawData.end(); ++it) {
3629+
if (it->topic) free(it->topic);
3630+
if (it->payload) free(it->payload);
3631+
}
3632+
36173633
RSCP_MQTT::RscpMqttCache.clear();
36183634
RSCP_MQTT::RscpMqttCacheTempl.clear();
36193635
RSCP_MQTT::RscpMqttReceiveCache.clear();
@@ -3623,6 +3639,7 @@ int main(int argc, char *argv[]) {
36233639
RSCP_MQTT::TopicStore.clear();
36243640
RSCP_MQTT::IdlePeriodCache.clear();
36253641
RSCP_MQTT::ErrorCache.clear();
3642+
RSCP_MQTT::rawData.clear();
36263643

36273644
// MQTT disconnect
36283645
mosquitto_disconnect(mosq);
@@ -3638,6 +3655,7 @@ int main(int argc, char *argv[]) {
36383655
if (cfg.curl_opt_cainfo) free(cfg.curl_opt_cainfo);
36393656
if (cfg.curl_opt_sslcert) free (cfg.curl_opt_sslcert);
36403657
if (cfg.curl_opt_sslkey) free(cfg.curl_opt_sslkey);
3658+
if (cfg.curl_protocol) free(cfg.curl_protocol);
36413659
#endif
36423660

36433661
if (cfg.logfile) free(cfg.logfile);

RscpProtocol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ bool RscpProtocol::allocateMemory(SRscpValue* value, size_t size) {
291291
if(size == 0) {
292292
return true;
293293
}
294-
value->data = (uint8_t *) malloc(size);
294+
value->data = (uint8_t *) malloc(size + 8); //fix?
295295
return (value->data != NULL);
296296
}
297297
else {
298298
// if data is already allocated -> reallocate to the correct size
299-
uint8_t *ucTmp = (uint8_t *) realloc(value->data, size);
299+
uint8_t *ucTmp = (uint8_t *) realloc(value->data, size + 8); //fix?
300300
if(ucTmp != NULL) {
301301
value->data = ucTmp;
302302
return true;
@@ -375,7 +375,7 @@ int32_t RscpProtocol::parseData(const uint8_t* data, const uint32_t & length, st
375375
newVal.length = value->length;
376376
if(value->length > 0) {
377377
// allocate data memory for each value separately
378-
newVal.data = (uint8_t *) malloc(value->length);
378+
newVal.data = (uint8_t *) malloc(value->length + 8); //fix?
379379
if(newVal.data == NULL) {
380380
// not enough memory, return only what parsed until now
381381
destroyValueData(vecValues);

0 commit comments

Comments
 (0)