From ee8fec3143d514776da67768c652cf0ced6ac1ed Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 20 Nov 2019 12:25:38 +0000 Subject: [PATCH] ECC-991: Memory leak fix and cleanup --- src/bufr_util.c | 42 ++++++++++++++++++------------------ tests/bufr_extract_headers.c | 4 ++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/bufr_util.c b/src/bufr_util.c index af8b1ba4b..2fa6ec089 100644 --- a/src/bufr_util.c +++ b/src/bufr_util.c @@ -759,30 +759,30 @@ int codes_bufr_header_get_string(codes_bufr_header* bh, const char* key, char *v if (!isEcmwfLocal || bh->ident == NULL || strlen(bh->ident)==0) strcpy(val, NOT_FOUND); else *len = sprintf(val, "%s", bh->ident); } - else if (strcmp(key, "localYear")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localYear); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localMonth")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localMonth); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localDay")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localDay); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localHour); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localYear")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localYear); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localMonth")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localMonth); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localDay")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localDay); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localHour); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "localMinute")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localMinute); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "localSecond")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localSecond); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "rdbtimeDay")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeDay); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rdbtimeHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeHour); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rdbtimeMinute")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeMinute); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rdbtimeSecond")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeSecond); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rectimeDay")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeDay); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rectimeHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeHour); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rectimeMinute")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeMinute); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "rectimeSecond")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeSecond); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "isSatellite")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->isSatellite); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLongitude1")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude1); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLatitude1")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude1); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLongitude2")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude2); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLatitude2")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude2); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLatitude")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "localLongitude")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "qualityControl")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->qualityControl); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "newSubtype")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->newSubtype); else strcpy(val, NOT_FOUND); } - else if (strcmp(key, "daLoop")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->daLoop); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rdbtimeHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeHour); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rdbtimeMinute")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeMinute); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rdbtimeSecond")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rdbtimeSecond); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rectimeDay")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeDay); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rectimeHour")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeHour); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rectimeMinute")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeMinute); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "rectimeSecond")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->rectimeSecond); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "isSatellite")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->isSatellite); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLongitude1")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude1); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLatitude1")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude1); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLongitude2")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude2); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLatitude2")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude2); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLatitude")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLatitude); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "localLongitude")==0) { if (isEcmwfLocal) *len = sprintf(val, "%g", bh->localLongitude); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "qualityControl")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->qualityControl); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "newSubtype")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->newSubtype); else strcpy(val, NOT_FOUND); } + else if (strcmp(key, "daLoop")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->daLoop); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "localNumberOfObservations")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->localNumberOfObservations); else strcpy(val, NOT_FOUND); } else if (strcmp(key, "satelliteID")==0) { if (isEcmwfLocal) *len = sprintf(val, "%ld", bh->satelliteID); else strcpy(val, NOT_FOUND); } diff --git a/tests/bufr_extract_headers.c b/tests/bufr_extract_headers.c index e2a7e8769..fc5d940e6 100644 --- a/tests/bufr_extract_headers.c +++ b/tests/bufr_extract_headers.c @@ -23,6 +23,7 @@ int main(int argc, char* argv[]) int requested_print_keys_count = MAX_KEYS; codes_values requested_print_keys[MAX_KEYS]; + /* Usage: prog keys file */ assert (argc == 3); keys = argv[1]; /* comma-separated like bufr_ls/bufr_get */ @@ -50,6 +51,9 @@ int main(int argc, char* argv[]) } free(header_array); + for (i=0; i