Skip to content

Commit 60d6bec

Browse files
committed
Fix memoryleaks
1 parent 7a33c51 commit 60d6bec

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

FPS_GT511C3/FPS_GT511C3.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ void FPS_GT511C3::Open()
244244
cp->Parameter[2] = 0x00;
245245
cp->Parameter[3] = 0x00;
246246
byte* packetbytes = cp->GetPacketBytes();
247+
delete cp;
247248
SendCommand(packetbytes, 12);
248249
Response_Packet* rp = GetResponse();
249250
delete rp;
@@ -262,6 +263,7 @@ void FPS_GT511C3::Close()
262263
cp->Parameter[2] = 0x00;
263264
cp->Parameter[3] = 0x00;
264265
byte* packetbytes = cp->GetPacketBytes();
266+
delete cp;
265267
SendCommand(packetbytes, 12);
266268
Response_Packet* rp = GetResponse();
267269
delete rp;
@@ -289,13 +291,13 @@ bool FPS_GT511C3::SetLED(bool on)
289291
cp->Parameter[2] = 0x00;
290292
cp->Parameter[3] = 0x00;
291293
byte* packetbytes = cp->GetPacketBytes();
294+
delete cp;
292295
SendCommand(packetbytes, 12);
293296
Response_Packet* rp = GetResponse();
294297
bool retval = true;
295298
if (rp->ACK == false) retval = false;
296299
delete rp;
297300
delete packetbytes;
298-
delete cp;
299301
return retval;
300302
};
301303

@@ -313,6 +315,7 @@ bool FPS_GT511C3::ChangeBaudRate(int baud)
313315
cp->Command = Command_Packet::Commands::Open;
314316
cp->ParameterFromInt(baud);
315317
byte* packetbytes = cp->GetPacketBytes();
318+
delete cp;
316319
SendCommand(packetbytes, 12);
317320
Response_Packet* rp = GetResponse();
318321
bool retval = rp->ACK;
@@ -340,6 +343,7 @@ int FPS_GT511C3::GetEnrollCount()
340343
cp->Parameter[2] = 0x00;
341344
cp->Parameter[3] = 0x00;
342345
byte* packetbytes = cp->GetPacketBytes();
346+
delete cp;
343347
SendCommand(packetbytes, 12);
344348
Response_Packet* rp = GetResponse();
345349

@@ -488,6 +492,7 @@ bool FPS_GT511C3::IsPressFinger()
488492
Command_Packet* cp = new Command_Packet();
489493
cp->Command = Command_Packet::Commands::IsPressFinger;
490494
byte* packetbytes = cp->GetPacketBytes();
495+
delete cp;
491496
SendCommand(packetbytes, 12);
492497
Response_Packet* rp = GetResponse();
493498
bool retval = false;
@@ -498,7 +503,6 @@ bool FPS_GT511C3::IsPressFinger()
498503
if (pval == 0) retval = true;
499504
delete rp;
500505
delete packetbytes;
501-
delete cp;
502506
return retval;
503507
}
504508

@@ -512,12 +516,12 @@ bool FPS_GT511C3::DeleteID(int id)
512516
cp->Command = Command_Packet::Commands::DeleteID;
513517
cp->ParameterFromInt(id);
514518
byte* packetbytes = cp->GetPacketBytes();
519+
delete cp;
515520
SendCommand(packetbytes, 12);
516521
Response_Packet* rp = GetResponse();
517522
bool retval = rp->ACK;
518523
delete rp;
519524
delete packetbytes;
520-
delete cp;
521525
return retval;
522526
}
523527

@@ -552,6 +556,7 @@ int FPS_GT511C3::Verify1_1(int id)
552556
cp->Command = Command_Packet::Commands::Verify1_1;
553557
cp->ParameterFromInt(id);
554558
byte* packetbytes = cp->GetPacketBytes();
559+
delete cp;
555560
SendCommand(packetbytes, 12);
556561
Response_Packet* rp = GetResponse();
557562
int retval = 0;
@@ -564,7 +569,6 @@ int FPS_GT511C3::Verify1_1(int id)
564569
}
565570
delete rp;
566571
delete packetbytes;
567-
delete cp;
568572
return retval;
569573
}
570574

@@ -578,13 +582,13 @@ int FPS_GT511C3::Identify1_N()
578582
Command_Packet* cp = new Command_Packet();
579583
cp->Command = Command_Packet::Commands::Identify1_N;
580584
byte* packetbytes = cp->GetPacketBytes();
585+
delete cp;
581586
SendCommand(packetbytes, 12);
582587
Response_Packet* rp = GetResponse();
583588
int retval = rp->IntFromParameter();
584589
if (retval > 200) retval = 200;
585590
delete rp;
586591
delete packetbytes;
587-
delete cp;
588592
return retval;
589593
}
590594

@@ -606,12 +610,12 @@ bool FPS_GT511C3::CaptureFinger(bool highquality)
606610
cp->ParameterFromInt(0);
607611
}
608612
byte* packetbytes = cp->GetPacketBytes();
613+
delete cp;
609614
SendCommand(packetbytes, 12);
610615
Response_Packet* rp = GetResponse();
611616
bool retval = rp->ACK;
612617
delete rp;
613618
delete packetbytes;
614-
delete cp;
615619
return retval;
616620

617621
}
@@ -761,8 +765,8 @@ void FPS_GT511C3::SendToSerial(byte data[], int length)
761765
Serial.print("\"");
762766
for(int i=0; i<length; i++)
763767
{
764-
if (first) first=false; else Serial.print(" ");
765-
serialPrintHex(data[i]);
768+
if (first) first=false; else Serial.print(" ");
769+
serialPrintHex(data[i]);
766770
}
767771
Serial.print("\"");
768772
}

0 commit comments

Comments
 (0)