Skip to content

Commit

Permalink
Fixed a memory leak, removed some old code
Browse files Browse the repository at this point in the history
  • Loading branch information
computergeek125 committed Mar 28, 2017
1 parent 9ae7a0d commit e4f139b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions dscom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ void DSCom::read() {
if (!messagewalk) s->println("READY");
#endif
messagewalk = true;
//cts();
if (s->available() > 1) {
#ifdef DSCOM_DEBUG_2
s->print("Peek: ");
Expand Down Expand Up @@ -49,8 +48,6 @@ void DSCom::read() {
#ifdef DSCOM_DEBUG_1
s->println("Data read");
#endif
// Update len for future use (writing)
//data_len = len;
uint16_t packetCrc = getTwoBytesSerial();
uint16_t calculatedCrc = crc.XModemCrc(new_data, 0, len);
#ifdef DSCOM_DEBUG_1
Expand All @@ -65,6 +62,7 @@ void DSCom::read() {
#ifdef DSCOM_DEBUG_1
s->println("CRC doesn't match");
#endif
free(new_data);
state = DSCOM_STATE_READY;
}
else
Expand All @@ -78,11 +76,9 @@ void DSCom::read() {
if (!messagewalk) s->println("APPLY");
#endif
messagewalk = false;
uint8_t* old_data;
old_data = data;
free(data);
data = new_data;
data_len = new_data_len;
free(old_data);
#ifdef DSCOM_DEBUG_2
s->println("Done applying");
#endif
Expand Down Expand Up @@ -127,7 +123,6 @@ void DSCom::readData(uint16_t len) {
new_data_len = len;
new_data = (uint8_t*)malloc(sizeof(uint8_t)*len);
while ((uint16_t)s->available() < len) {}

// Read in data from serial
s->readBytes(new_data, len);
}
Expand Down
2 changes: 1 addition & 1 deletion dscom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef DSCom_H
#define DSCom_H
#define LIBRARY_VERSION_DSCOM_H "0.3.0-alpha"
#define LIBRARY_VERSION_DSCOM_H "0.3.1-alpha"

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
Expand Down

0 comments on commit e4f139b

Please sign in to comment.