Fixed some memory leak issues.

This commit is contained in:
Patrick Vogler 2024-10-30 12:38:56 +01:00
parent 6716a2b1d4
commit f81807e1e3
Signed by: Patrick Vogler
GPG key ID: 5536B08CE82E8509
2 changed files with 43 additions and 30 deletions

View file

@ -231,22 +231,36 @@ endian_conversion(void *value,
void
eas3_free_data(eas3_data* data)
{
if(data != NULL)
{
if (data->param_names != NULL)
free(data->param_names);
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
eas3_param_names *param, *temp;
if(data != NULL)
{
if (data->param_names != NULL)
{
param = data->param_names->root;
while(param != NULL)
{
temp = param;
param = param -> next;
free(temp);
}
}
if (data->field.d != NULL)
free(data->field.d);
if (data->field.d != NULL)
free(data->field.d);
if (data->field.f != NULL)
free(data->field.f);
if (data->field.f != NULL)
free(data->field.f);
if(data->aux.ptr != NULL)
free(data->aux.ptr);
if(data->aux.ptr != NULL)
free(data->aux.ptr);
free(data);
}
free(data);
}
}
void
@ -345,7 +359,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
\*-----------------------*/
uint64 Lread;
uint64 i;
uint8 precision;
/*-----------------------*\
! DEFINE CHAR VARIABLES: !
@ -356,7 +369,6 @@ read_eas3_header(FILE *const fp, eas3_data *const data)
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_inf *info;
eas3_std_params *params;
/*-----------------------*\
@ -702,7 +714,6 @@ write_eas3_header(FILE *const fp, eas3_data *const data)
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
bwc_gl_inf *info;
eas3_std_params *params;
eas3_param_names *param_names;

View file

@ -454,8 +454,6 @@ parse_opt(int key,
! DEFINE STRUCTS: !
\*-----------------------*/
cli_arguments *arguments;
bwc_codec *codec;
bwc_stream *stream;
/*-----------------------*\
! DEFINE ASSERTIONS: !
@ -720,7 +718,7 @@ parse_opt(int key,
else
{
errno = 0;
argp_error(state, "The specified bitrate (%d) is "
argp_error(state, "The specified compression ratio (%f) is "
"out of the supported range.\n", compRatio);
}
}
@ -838,7 +836,7 @@ parse_opt(int key,
}
for(token = strtok_r(arg, ",", &ptr), i = 0;
token != NULL, i < 4;
token != NULL && i < 4;
token = strtok_r(NULL, ",", &ptr), i++)
{
if (strcasecmp(token, "leGall") == 0)
@ -1047,6 +1045,7 @@ parse_opt(int key,
{
if (arguments->mode == cli_ini)
argp_usage (state);
break;
}
/* Return error if key is unknown. */
@ -1061,7 +1060,7 @@ parse_opt(int key,
* @details Initialize the argp struct. used to parse the command line arguments
*/
/*================================================================================================*/
static struct argp argp = {options, parse_opt, 0, doc};
static struct argp argp = {options, parse_opt, 0, doc, 0, 0, 0};
/*================================================================================================*/
/**
@ -1087,7 +1086,7 @@ int main(int argc, char *argv[])
\*-----------------------*/
uint64_t size = 0;
uint8_t i;
uint8_t error_handle;
uint8_t error_handle = EXIT_SUCCESS;
/*-----------------------*\
! DEFINE REAL VARIABLES: !
@ -1101,28 +1100,28 @@ int main(int argc, char *argv[])
char cli_buffer[1024] = {0};
char cli_verbose[4096] = {0};
char *cli_output;
char *buffer;
char *cli_output = NULL;
char *buffer = NULL;
unsigned char *input;
unsigned char *output;
unsigned char *input = NULL;
unsigned char *output = NULL;
/*-----------------------*\
! DEFINE FILE POINTER: !
\*-----------------------*/
FILE *fp;
FILE *fp = NULL;
/*-----------------------*\
! DEFINE DER. VARIABLES: !
\*-----------------------*/
bwc_precision precision;
bwc_stream *stream;
bwc_codec *coder;
bwc_stream *stream = NULL;
bwc_codec *coder = NULL;
/*-----------------------*\
! DEFINE STRUCTS: !
\*-----------------------*/
eas3_data *data;
eas3_data *data = NULL;
cli_arguments arguments = {0};
/* Parse the command line arguments and invoke the appro- *
@ -1173,7 +1172,7 @@ int main(int argc, char *argv[])
printf(TYPERROR);
goto OUT;
}
cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 1, sizeof(char));
cli_output = calloc(strlen(arguments.out) - strlen(buffer) + 5, sizeof(char));
if (cli_output == NULL)
{
error_handle = EXIT_FAILURE;
@ -1471,5 +1470,8 @@ OUT:
if (cli_output != NULL)
free(cli_output);
if (fp != NULL)
fclose(fp);
return error_handle;
}