Hello all,
Just in case, I like to share some memory issues discovered by me.
- Resource leak (s)
Location: ./platforms/nuttx/NuttX/apps/canutils/cansend/cansend.c
Description: there is not releasing allocated resource at line 117
/* open socket */
if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
perror("socket");
return 1;
}
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
if (!ifr.ifr_ifindex) {
perror("if_nametoindex");
// ERROR
return 1;
}
- Idempotent assignment
Location: ./src/drivers/magnetometer/lsm9ds1_mag/LSM9DS1_MAG.cpp
Description: Redundant assignment of ‘y’ to itself at line 179
// sensor Z is up (RHC), flip z for publication
// sensor X is aligned with -X of lsm9ds1 accel/gyro
x = (x == INT16_MIN) ? INT16_MAX : -x;
y = y; // Idempotent assignment
z = (z == INT16_MIN) ? INT16_MAX : -z;
- Dereferencing deallocated data
Location: ./src./drivers/px4io/px4io.cpp
Description: dereferencing ‘interface’ after it is deallocated at line 3151
#ifdef PX4IO_SERIAL_BASE
interface = PX4IO_serial_interface();
#endifif (interface != nullptr) {
goto got;
}errx(1, “cannot alloc interface”);
got:
if (interface->init() != OK) {
delete interface;
errx(1, “interface init failed”);
}// ERROR
return interface;
- Resource leak (file_buf)
Location: ./src/drivers/tap_esc/tap_esc_uploader.cpp
Description: there is not releasing allocated resource at line 1113
file_buf = new uint8_t[PROG_MULTI_MAX];
PX4_DEBUG(“verify…”);
lseek(_fw_fd, 0, SEEK_SET);ret = get_device_info(esc_id, PROTO_GET_DEVICE, PROTO_DEVICE_FW_SIZE, fw_size_remote);
if (ret != OK) {
PX4_DEBUG(“could not read firmware size”);// ERROR return ret;
}
It would be nice if these memory issues will be resolved. Thanks!