Skip to content

Commit

Permalink
fix valgrind-found use-after-free in fitsioutils
Browse files Browse the repository at this point in the history
  • Loading branch information
dstndstn committed Dec 2, 2024
1 parent 8c6ff4b commit 74ee194
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions util/fitsioutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,14 @@ void fits_header_add_int(qfits_header* hdr, const char* key, int val,
int fits_update_value(qfits_header* hdr, const char* key, const char* newvalue) {
// update the FITS header value, keeping the key and comment constant
char* comment = qfits_header_getcom(hdr, key);
// we have to make a temporary copy of "comment" because qfits_header_mod will
// free an existing comment -- the same memory we have in "comment".
// This bug existed for at least 8 years. So much for our unit tests!
if (comment)
comment = strdup(comment);
qfits_header_mod(hdr, key, newvalue, comment);
if (comment)
free(comment);
return 0;
}

Expand Down

0 comments on commit 74ee194

Please sign in to comment.