-
Notifications
You must be signed in to change notification settings - Fork 31
gcc-15 -fanalyzer fixes #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
d47f5e6
4c67961
0e13f7b
13d199e
5be6f05
d94c176
80580b3
9c87d31
815f0a3
8489cd6
276fe2f
750eab4
1fe73fa
e95ad20
4c3b60a
aecf936
fb39f84
c656bdb
9e94e25
a3b2802
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1183,6 +1183,7 @@ PRIVATE void update_history(int mincid, char *arg_string) | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /* Allocate a string and get the old history */ | ||||||||||||||||||||||||||||||||||||||||||||
| string = MALLOC(att_length, char); | ||||||||||||||||||||||||||||||||||||||||||||
| if (string == NULL) return; | ||||||||||||||||||||||||||||||||||||||||||||
| string[0] = '\0'; | ||||||||||||||||||||||||||||||||||||||||||||
| (void) miattgetstr(mincid, NC_GLOBAL, MIhistory, att_length, | ||||||||||||||||||||||||||||||||||||||||||||
| string); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2007,6 +2008,7 @@ PRIVATE Loopfile_Info *initialize_loopfile_info(int num_input_files, | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /* Allocate structure */ | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info = MALLOC(1, Loopfile_Info); | ||||||||||||||||||||||||||||||||||||||||||||
| if (loopfile_info == NULL) return NULL; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /* Save clobber info */ | ||||||||||||||||||||||||||||||||||||||||||||
| if (loop_options->clobber) { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2029,6 +2031,7 @@ PRIVATE Loopfile_Info *initialize_loopfile_info(int num_input_files, | |||||||||||||||||||||||||||||||||||||||||||
| /* Save input file names (just copy pointers, not strings) */ | ||||||||||||||||||||||||||||||||||||||||||||
| if (num_input_files > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->input_files = MALLOC(num_input_files, char *); | ||||||||||||||||||||||||||||||||||||||||||||
| if (loopfile_info->input_files == NULL) { FREE(loopfile_info); return NULL; } | ||||||||||||||||||||||||||||||||||||||||||||
| for (ifile=0; ifile < num_input_files; ifile++) | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->input_files[ifile] = input_files[ifile]; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2038,6 +2041,7 @@ PRIVATE Loopfile_Info *initialize_loopfile_info(int num_input_files, | |||||||||||||||||||||||||||||||||||||||||||
| /* Save output file names (just copy pointers, not strings) */ | ||||||||||||||||||||||||||||||||||||||||||||
| if (num_output_files > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->output_files = MALLOC(num_output_files, char *); | ||||||||||||||||||||||||||||||||||||||||||||
| if (loopfile_info->output_files == NULL) { FREE(loopfile_info); return NULL; } | ||||||||||||||||||||||||||||||||||||||||||||
| for (ifile=0; ifile < num_output_files; ifile++) | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->output_files[ifile] = output_files[ifile]; | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2061,6 +2065,9 @@ PRIVATE Loopfile_Info *initialize_loopfile_info(int num_input_files, | |||||||||||||||||||||||||||||||||||||||||||
| num_free_files -= num_files; | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->output_mincid = MALLOC(num_files, int); | ||||||||||||||||||||||||||||||||||||||||||||
| loopfile_info->output_icvid = MALLOC(num_files, int); | ||||||||||||||||||||||||||||||||||||||||||||
| if (loopfile_info->output_mincid == NULL || loopfile_info->output_icvid == NULL) { | ||||||||||||||||||||||||||||||||||||||||||||
| FREE(loopfile_info); return NULL; | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| FREE(loopfile_info); return NULL; | |
| if (loopfile_info->output_mincid != NULL) FREE(loopfile_info->output_mincid); | |
| if (loopfile_info->output_icvid != NULL) FREE(loopfile_info->output_icvid); | |
| if (loopfile_info->output_files != NULL) FREE(loopfile_info->output_files); | |
| if (loopfile_info->input_files != NULL) FREE(loopfile_info->input_files); | |
| FREE(loopfile_info); | |
| return NULL; |
Copilot
AI
Apr 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On allocation failure for input_mincid/input_icvid, the code frees only loopfile_info, leaking earlier allocations such as input_files, output_files, and output_mincid/output_icvid. Use a cleanup path that frees all partially allocated members before returning.
| FREE(loopfile_info); return NULL; | |
| if (loopfile_info->input_mincid != NULL) { | |
| FREE(loopfile_info->input_mincid); | |
| } | |
| if (loopfile_info->input_icvid != NULL) { | |
| FREE(loopfile_info->input_icvid); | |
| } | |
| if (loopfile_info->output_mincid != NULL) { | |
| FREE(loopfile_info->output_mincid); | |
| } | |
| if (loopfile_info->output_icvid != NULL) { | |
| FREE(loopfile_info->output_icvid); | |
| } | |
| if (loopfile_info->input_files != NULL) { | |
| FREE(loopfile_info->input_files); | |
| } | |
| if (loopfile_info->output_files != NULL) { | |
| FREE(loopfile_info->output_files); | |
| } | |
| FREE(loopfile_info); | |
| return NULL; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,6 +97,7 @@ int micopy_dimension ( midimhandle_t dim_ptr, midimhandle_t *new_dim_ptr ) | |||||||||
| handle->offsets = ( double * ) malloc ( dim_ptr->length * sizeof ( double ) ); | ||||||||||
|
|
||||||||||
| if ( handle->offsets == NULL ) { | ||||||||||
| free(handle->name); | ||||||||||
| free(handle); | ||||||||||
| return ( MI_ERROR ); | ||||||||||
| } | ||||||||||
|
|
@@ -133,6 +134,10 @@ int micopy_dimension ( midimhandle_t dim_ptr, midimhandle_t *new_dim_ptr ) | |||||||||
| handle->widths = ( double * ) malloc ( dim_ptr->length * sizeof ( double ) ); | ||||||||||
|
|
||||||||||
| if ( handle->widths == NULL ) { | ||||||||||
| free(handle->name); | ||||||||||
| free(handle->offsets); | ||||||||||
| free(handle->units); | ||||||||||
| free(handle); | ||||||||||
| return ( MI_ERROR ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -275,6 +280,8 @@ int micreate_dimension(const char *name, midimclass_t dimclass, midimattr_t attr | |||||||||
| break; | ||||||||||
| case MI_DIMCLASS_ANY: | ||||||||||
| default: | ||||||||||
| free(handle->comments); | ||||||||||
| free(handle->name); | ||||||||||
| free(handle); | ||||||||||
| return MI_ERROR; | ||||||||||
| } | ||||||||||
|
|
@@ -285,6 +292,13 @@ int micreate_dimension(const char *name, midimclass_t dimclass, midimattr_t attr | |||||||||
| if ( attr & MI_DIMATTR_NOT_REGULARLY_SAMPLED ) { | ||||||||||
| handle->widths = ( double * ) malloc ( length * sizeof ( double ) ); | ||||||||||
|
|
||||||||||
| if ( handle->widths == NULL ) { | ||||||||||
| free(handle->comments); | ||||||||||
| free(handle->name); | ||||||||||
| free(handle); | ||||||||||
| return ( MI_ERROR ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for ( i = 0; i < length; i++ ) { | ||||||||||
|
|
||||||||||
| handle->widths[i] = 1.0; | ||||||||||
|
|
@@ -482,6 +496,8 @@ int miset_apparent_dimension_order ( mihandle_t volume, int array_length, | |||||||||
| */ | ||||||||||
| if ( volume->dim_indices == NULL ) { | ||||||||||
| volume->dim_indices = ( int * ) malloc ( volume->number_of_dims * sizeof ( int ) ); | ||||||||||
| if ( volume->dim_indices == NULL ) | ||||||||||
| return ( MI_ERROR ); | ||||||||||
| memset ( volume->dim_indices, -1, sizeof ( volume->number_of_dims ) ); | ||||||||||
|
||||||||||
| memset ( volume->dim_indices, -1, sizeof ( volume->number_of_dims ) ); | |
| memset ( volume->dim_indices, -1, | |
| volume->number_of_dims * sizeof ( *volume->dim_indices ) ); |
Copilot
AI
Apr 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same memset sizing bug as above: sizeof(volume->number_of_dims) does not cover the allocated dim_indices array. Initialize volume->dim_indices using volume->number_of_dims * sizeof(*volume->dim_indices) (or a loop).
| memset ( volume->dim_indices, -1, sizeof ( volume->number_of_dims ) ); | |
| for ( i = 0; i < volume->number_of_dims; i++ ) { | |
| volume->dim_indices[i] = -1; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -95,6 +95,10 @@ int milist_start ( mihandle_t vol, const char *path, int flags, | |||||||
| } | ||||||||
|
|
||||||||
| frame = ( struct milistframe * ) malloc ( sizeof ( struct milistframe ) ); | ||||||||
| if ( frame == NULL ) { | ||||||||
|
||||||||
| if ( frame == NULL ) { | |
| if ( frame == NULL ) { | |
| H5Gclose ( grp_id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
output_filesallocation fails, the code frees onlyloopfile_infobut leaksloopfile_info->input_filesallocated earlier (and leaves other members potentially uninitialized). Consider initializing the struct members to NULL/MI_ERROR up front and callingcleanup_loopfile_info()(or manually freeing prior allocations) on all early-return error paths.