- Replace data structure related malloc() & free() calls to ND_DataStruct_Alloc() ND_DataStruct_Free() calls.

This commit is contained in:
Arnaud G. GIBERT 2024-05-03 17:39:28 +02:00
parent 5cce284879
commit 34f661368d

View File

@ -107,7 +107,11 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N
Command_Name = "NDD_CMD_VALUE_ALLOC"; Command_Name = "NDD_CMD_VALUE_ALLOC";
if( ( *Layer_Ptr_Ptr = (DRT_Layer *)malloc( sizeof( DRT_Layer))) != NULL) if( ND_DataStruct_Alloc( (void **)Layer_Ptr_Ptr, Root_Ptr, sizeof( DRT_Layer), NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{ {
( *Layer_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; ( *Layer_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number;
@ -124,10 +128,6 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N
return( NDS_OK); return( NDS_OK);
} }
else
{
return( NDS_KO);
}
} }
case NDD_CMD_VALUE_FREE: case NDD_CMD_VALUE_FREE:
@ -140,10 +140,15 @@ NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_N
DR_Layer_Sample_UnLoad( Layer_Ptr); DR_Layer_Sample_UnLoad( Layer_Ptr);
free( Layer_Ptr); if( ND_DataStruct_Free( (void *)Layer_Ptr, Root_Ptr, NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{
return( NDS_OK); return( NDS_OK);
} }
}
case NDD_CMD_VALUE_COMP: case NDD_CMD_VALUE_COMP:
{ {
@ -469,7 +474,11 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id,
Command_Name = "NDD_CMD_VALUE_ALLOC"; Command_Name = "NDD_CMD_VALUE_ALLOC";
if( ( *Instrument_Ptr_Ptr = (DRT_Instrument *)malloc( sizeof( DRT_Instrument))) != NULL) if( ND_DataStruct_Alloc( (void **)Instrument_Ptr_Ptr, Root_Ptr, sizeof( DRT_Instrument), NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{ {
( *Instrument_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; ( *Instrument_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number;
@ -491,10 +500,6 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id,
return( NDS_OK); return( NDS_OK);
} }
} }
else
{
return( NDS_KO);
}
} }
case NDD_CMD_VALUE_FREE: case NDD_CMD_VALUE_FREE:
@ -512,10 +517,15 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id,
return( DRS_KO); return( DRS_KO);
} }
free( Instrument_Ptr); if( ND_DataStruct_Free( (void *)Instrument_Ptr, Root_Ptr, NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{
return( NDS_OK); return( NDS_OK);
} }
}
case NDD_CMD_VALUE_COMP: case NDD_CMD_VALUE_COMP:
{ {
@ -895,7 +905,11 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod
Command_Name = "NDD_CMD_VALUE_ALLOC"; Command_Name = "NDD_CMD_VALUE_ALLOC";
if( ( *Kit_Ptr_Ptr = (DRT_Kit *)malloc( sizeof( DRT_Kit))) != NULL) if( ND_DataStruct_Alloc( (void **)Kit_Ptr_Ptr, Root_Ptr, sizeof( DRT_Kit), NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{ {
( *Kit_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; ( *Kit_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number;
( *Kit_Ptr_Ptr)->Logical_Id = Kit_Template_Ptr->Logical_Id; ( *Kit_Ptr_Ptr)->Logical_Id = Kit_Template_Ptr->Logical_Id;
@ -915,10 +929,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod
return( NDS_OK); return( NDS_OK);
} }
else
{
return( NDS_KO);
}
} }
case NDD_CMD_VALUE_FREE: case NDD_CMD_VALUE_FREE:
@ -936,10 +946,15 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod
return( DRS_KO); return( DRS_KO);
} }
free( Kit_Ptr); if( ND_DataStruct_Free( (void *)Kit_Ptr, Root_Ptr, NULL) != NDS_OK)
{
return( NDS_KO);
}
else
{
return( NDS_OK); return( NDS_OK);
} }
}
case NDD_CMD_VALUE_COMP: case NDD_CMD_VALUE_COMP:
{ {
@ -1379,7 +1394,11 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
else else
{ {
fprintf( stderr, "Freeing SF_Info: [%s]\n", Layer_Ptr->FileName); fprintf( stderr, "Freeing SF_Info: [%s]\n", Layer_Ptr->FileName);
free( Layer_Ptr->SF_Info_Ptr );
if( ND_DataStruct_Free( (void *)Layer_Ptr->SF_Info_Ptr, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL) != NDS_OK)
{
return( DRS_KO);
}
} }
} }
else else
@ -1387,11 +1406,15 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
if( Layer_Ptr->Sample_Ptr != NULL) if( Layer_Ptr->Sample_Ptr != NULL)
{ {
fprintf( stderr, "Freeing Sample: [%s]\n", Layer_Ptr->FileName); fprintf( stderr, "Freeing Sample: [%s]\n", Layer_Ptr->FileName);
free( Layer_Ptr->Sample_Ptr);
if( ND_DataStruct_Free( (void *)Layer_Ptr->Sample_Ptr, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL) != NDS_OK)
{
return( DRS_KO);
}
} }
} }
if( ( Layer_Ptr->SF_Info_Ptr = malloc( sizeof(SF_INFO))) == NULL) if( ND_DataStruct_Alloc( (void **)&( Layer_Ptr->SF_Info_Ptr), Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, sizeof( SF_INFO), NULL) != NDS_OK)
{ {
fprintf( stderr, "Can't allocate SF_Info buffer!\n"); fprintf( stderr, "Can't allocate SF_Info buffer!\n");
return( DRS_KO); return( DRS_KO);
@ -1415,7 +1438,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
{ {
Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels; Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels;
if( ( Layer_Ptr->Sample_Ptr = malloc( Layer_Ptr->Sample_Size * sizeof( float))) == NULL) if( ND_DataStruct_Alloc( (void **)&( Layer_Ptr->Sample_Ptr), Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, ( Layer_Ptr->Sample_Size * sizeof( float)), NULL) != NDS_OK)
{ {
fprintf(stderr,"Can't allocate sample memory: (%ld) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName); fprintf(stderr,"Can't allocate sample memory: (%ld) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName);
status = DRS_KO; status = DRS_KO;
@ -1443,7 +1466,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
out_size = src_data.output_frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); out_size = src_data.output_frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float);
if( ( src_data.data_out = malloc( out_size)) == NULL) if( ND_DataStruct_Alloc( (void **)&( src_data.data_out), Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, out_size, NULL) != NDS_OK)
{ {
fprintf( stderr,"Can't allocate resample memory: (%ld) for [%s]!\n", out_size, Layer_Ptr->FileName); fprintf( stderr,"Can't allocate resample memory: (%ld) for [%s]!\n", out_size, Layer_Ptr->FileName);
status = DRS_KO; status = DRS_KO;
@ -1455,7 +1478,9 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
{ {
fprintf( stderr,"Can't convert rate for [%s]: [%s]\n", Layer_Ptr->FileName, src_strerror( src_status)); fprintf( stderr,"Can't convert rate for [%s]: [%s]\n", Layer_Ptr->FileName, src_strerror( src_status));
free( src_data.data_out); ND_DataStruct_Free( (void *)src_data.data_out, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL);
status = DRS_KO;
} }
else else
{ {
@ -1465,7 +1490,7 @@ DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr)
src_data.input_frames_used, Layer_Ptr->SF_Info_Ptr->frames, src_data.output_frames_gen); src_data.input_frames_used, Layer_Ptr->SF_Info_Ptr->frames, src_data.output_frames_gen);
} }
free( Layer_Ptr->Sample_Ptr); ND_DataStruct_Free( (void *)Layer_Ptr->Sample_Ptr, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL);
Layer_Ptr->Sample_Ptr = src_data.data_out; Layer_Ptr->Sample_Ptr = src_data.data_out;
Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels; Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels;
@ -1499,16 +1524,23 @@ DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *Layer_Ptr)
if( Layer_Ptr->Sample_Ptr != NULL) if( Layer_Ptr->Sample_Ptr != NULL)
{ {
// fprintf( stderr, "Freeing Sample!\n"); // fprintf( stderr, "Freeing Sample!\n");
free( Layer_Ptr->Sample_Ptr);
if( ND_DataStruct_Free( (void *)Layer_Ptr->Sample_Ptr, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL) != NDS_OK)
{
return( DRS_KO);
}
} }
if( Layer_Ptr->SF_Info_Ptr != NULL) if( Layer_Ptr->SF_Info_Ptr != NULL)
{ {
// fprintf( stderr, "Freeing SF_Info!\n"); // fprintf( stderr, "Freeing SF_Info!\n");
free( Layer_Ptr->SF_Info_Ptr); if( ND_DataStruct_Free( (void *)Layer_Ptr->SF_Info_Ptr, Layer_Ptr->Instrument_Ptr->Layer_DS_Ptr, NULL) != NDS_OK)
{
return( DRS_KO);
}
} }
return( NDS_OK); return( DRS_OK);
} }