Skip to content

Commit

Permalink
Per #1777, fixing memory management in DbfHeader::set_subrecords(). I…
Browse files Browse the repository at this point in the history
…t is dynamically allocating a buffer based on the record_legnth (e.g. 5) but then reading 32 characters into it! Deleting the dynamically allocated buf variable causes it to abort. Since we always read 32 bytes here, switch to a static buffer of that size rather than dynamically allocating. (#1779)

Co-authored-by: John.H.Gotway@noaa.gov <John.H.Gotway@v72a1.ncep.noaa.gov>
  • Loading branch information
JohnHalleyGotway and John.H.Gotway@noaa.gov authored May 5, 2021
1 parent 30417be commit 01bdecb
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions met/src/libcode/vx_gis/dbf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,11 @@ void DbfHeader::set_subrecords(int fd)
int j;
int bytes, n_read;
int pos;
unsigned char * buf = 0;



subrec = new DbfSubRecord [n_subrecs];

buf = new unsigned char [record_length];
unsigned char buf[32];

//
// seek to the first record
Expand Down Expand Up @@ -360,8 +358,6 @@ for (j=0; j<n_subrecs; ++j) {
// done
//

if ( buf ) { delete [] buf; buf = 0; }

return;

}
Expand Down

0 comments on commit 01bdecb

Please sign in to comment.