fix AIS decoding memory leaks
This commit is contained in:
		
							parent
							
								
									e7b2c6e756
								
							
						
					
					
						commit
						8182ce1fe9
					
				| 
						 | 
				
			
			@ -898,7 +898,7 @@ public:
 | 
			
		|||
        registerConverter(128275UL, &N2kToNMEA0183Functions::HandleLog);
 | 
			
		||||
        registerConverter(127245UL, &N2kToNMEA0183Functions::HandleRudder);
 | 
			
		||||
        registerConverter(130310UL, &N2kToNMEA0183Functions::HandleWaterTemp);
 | 
			
		||||
#define HANDLE_AIS 1        
 | 
			
		||||
#define HANDLE_AIS         
 | 
			
		||||
#ifdef HANDLE_AIS
 | 
			
		||||
        registerConverter(129038UL, &N2kToNMEA0183Functions::HandleAISClassAPosReport);  // AIS Class A Position Report, Message Type 1
 | 
			
		||||
        registerConverter(129039UL, &N2kToNMEA0183Functions::HandleAISClassBMessage18);  // AIS Class B Position Report, Message Type 18
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,15 +68,13 @@ bool tNMEA0183AISMsg::AddIntToPayloadBin(int32_t ival, uint16_t countBits) {
 | 
			
		|||
 | 
			
		||||
  if ( (iAddPldBin + countBits ) >= AIS_BIN_MAX_LEN ) return false; // Is there room for any data
 | 
			
		||||
 | 
			
		||||
  bset = ival;
 | 
			
		||||
  AISBitSet bset(ival);
 | 
			
		||||
 | 
			
		||||
  PayloadBin[iAddPldBin]=0;
 | 
			
		||||
  uint16_t iAdd=iAddPldBin;
 | 
			
		||||
 | 
			
		||||
  char buf[1];
 | 
			
		||||
  for(int i = countBits-1; i >= 0 ; i--) {
 | 
			
		||||
    sprintf(buf, "%d", (int) bset[i]);
 | 
			
		||||
    PayloadBin[iAdd] = buf[0];
 | 
			
		||||
    PayloadBin[iAdd] = bset[i]?'1':'0';
 | 
			
		||||
    iAdd++;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -233,7 +231,7 @@ const char *tNMEA0183AISMsg::GetPayloadType5_Part1() {
 | 
			
		|||
  uint16_t lenbin = strlen( PayloadBin);
 | 
			
		||||
  if ( lenbin != 424 ) return nullptr;
 | 
			
		||||
 | 
			
		||||
  char *to = (char*) malloc(337);
 | 
			
		||||
  char to[337];
 | 
			
		||||
  strncpy(to, PayloadBin, 336);    // First Part is always 336 Length
 | 
			
		||||
  to[336]=0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -250,7 +248,7 @@ const char *tNMEA0183AISMsg::GetPayloadType5_Part2() {
 | 
			
		|||
  if ( lenbin != 424 ) return nullptr;
 | 
			
		||||
 | 
			
		||||
  lenbin = 88;        // Second Part is always 424 - 336 + 2 padding Zeros in Length
 | 
			
		||||
  char *to = (char*) malloc(91);
 | 
			
		||||
  char to[91];
 | 
			
		||||
  strncpy(to, PayloadBin + 336, lenbin);
 | 
			
		||||
  to[88]='0'; to[89]='0'; to[90]=0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -266,7 +264,7 @@ const char *tNMEA0183AISMsg::GetPayloadType24_PartA() {
 | 
			
		|||
  uint16_t lenbin = strlen( PayloadBin);
 | 
			
		||||
  if ( lenbin != 296 ) return nullptr;    // too short for Part A
 | 
			
		||||
 | 
			
		||||
  char *to = (char*) malloc(169);    // Part A has Length 168
 | 
			
		||||
  char to[169];    // Part A has Length 168
 | 
			
		||||
  *to = '\0';
 | 
			
		||||
  for (int i=0; i<168; i++){
 | 
			
		||||
    to[i] = PayloadBin[i];
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +282,7 @@ const char *tNMEA0183AISMsg::GetPayloadType24_PartA() {
 | 
			
		|||
const char *tNMEA0183AISMsg::GetPayloadType24_PartB() {
 | 
			
		||||
  uint16_t lenbin = strlen( PayloadBin);
 | 
			
		||||
  if ( lenbin != 296 ) return nullptr;    // too short for Part B
 | 
			
		||||
  char *to = (char*) malloc(169);    // Part B has Length 168
 | 
			
		||||
  char to[169];    // Part B has Length 168
 | 
			
		||||
  *to = '\0';
 | 
			
		||||
  for (int i=0; i<39; i++){
 | 
			
		||||
    to[i] = PayloadBin[i];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,10 +45,11 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 | 
			
		|||
 | 
			
		||||
#define BITSET_LENGTH 120
 | 
			
		||||
 | 
			
		||||
typedef std::bitset<BITSET_LENGTH> AISBitSet;
 | 
			
		||||
class tNMEA0183AISMsg : public tNMEA0183Msg {
 | 
			
		||||
 | 
			
		||||
  protected:  // AIS-NMEA
 | 
			
		||||
    std::bitset<BITSET_LENGTH> bset;
 | 
			
		||||
    AISBitSet bset;
 | 
			
		||||
    static const char *EmptyAISField;  // 6bits 0      not used yet.....
 | 
			
		||||
    static const char *AsciChar;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue