fix memory bugs in replay and bl_update

This commit is contained in:
Hyungsub
2021-08-18 07:45:51 +02:00
committed by GitHub
parent 810dbbd25b
commit d089d4a6a4
2 changed files with 6 additions and 1 deletions
+4
View File
@@ -416,11 +416,13 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
bool timestamp_found = findFieldOffset(orb_meta->o_fields, "timestamp", subscription->timestamp_offset, field_size);
if (!timestamp_found) {
delete subscription;
return true;
}
if (field_size != 8) {
PX4_ERR("Unsupported timestamp with size %i, ignoring the topic %s", field_size, orb_meta->o_name);
delete subscription;
return true;
}
@@ -429,6 +431,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
subscription->next_read_pos = this_message_pos; //this will be skipped
if (!nextDataMessage(file, *subscription, msg_id)) {
delete subscription;
return false;
}
@@ -436,6 +439,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
if (!subscription->orb_meta) {
//no message found. This is not a fatal error
delete subscription;
return true;
}
+2 -1
View File
@@ -142,7 +142,6 @@ bl_update_main(int argc, char *argv[])
#endif
uint8_t *buf = malloc(image_size);
memset(buf, 0xff, image_size);
if (buf == NULL)
{
@@ -151,6 +150,8 @@ bl_update_main(int argc, char *argv[])
return 1;
}
memset(buf, 0xff, image_size);
if (read(fd, buf, file_size) != file_size)
{
PX4_ERR("firmware read error");