nasa / trick

Trick Simulation Environment. Trick provides a common set of simulation capabilities and utilities to build simulations automatically.
Other
43 stars 21 forks source link

Resource leak in DPV_textbuffer.cpp #1561

Closed dandexter closed 1 year ago

dandexter commented 1 year ago

File: trick_source/data_products/DPX/DPV/UTILS/DPV_textbuffer.cpp Line: 129 Issue: When the number read is not 1 the function returns without closing the file. FROM:

numRead = fread((char *) buf, fileSize, 1, fp);
if (numRead != 1) {
    delete[]buf;
    return (-1);  // File was not closed!
}

TO:

numRead = fread((char *) buf, fileSize, 1, fp);
if (numRead != 1) {
    delete[]buf;
    fclose(fp);   // Make sure to close the file.
    return (-1);
}