A
Amit_Basnak
Dear Friends
I have two structures as below
typedef struct {
long_int length;
char data[1];
} CI_STRUCT_DATA;
typedef CI_STRUCT_DATA *ptr_CiStructData;
typedef struct {
char opener_ref_num_fmtd[26];
char our_ref_num[15];
char txn_ref_num[15];
char stop_tracer_date[27];
char tracer_trans_medium[3];
char tracer_frequency[2];
ptr_CiStructData MSG_DATA;
} CI_STRUCT_MSG;
I have allocated memory for it as below
CI_STRUCT_MSG msg_details;
msg_details.MSG_DATA = (CI_STRUCT_DATA *)
malloc( sizeof(CI_STRUCT_DATA) +(sizeof(unsigned
char)*(strlen(ptr_msg_details) + 1)) );
msg_details.MSG_DATA->length = strlen(ptr_msg_details);
strcpy((char *)msg_details.MSG_DATA->data,(char *)ptr_msg_details);
Im freeing up the memory as
free(ptr_msg_details);
Please suggest me any improvements in memory allocations if any
Thanks
Amit
I have two structures as below
typedef struct {
long_int length;
char data[1];
} CI_STRUCT_DATA;
typedef CI_STRUCT_DATA *ptr_CiStructData;
typedef struct {
char opener_ref_num_fmtd[26];
char our_ref_num[15];
char txn_ref_num[15];
char stop_tracer_date[27];
char tracer_trans_medium[3];
char tracer_frequency[2];
ptr_CiStructData MSG_DATA;
} CI_STRUCT_MSG;
I have allocated memory for it as below
CI_STRUCT_MSG msg_details;
msg_details.MSG_DATA = (CI_STRUCT_DATA *)
malloc( sizeof(CI_STRUCT_DATA) +(sizeof(unsigned
char)*(strlen(ptr_msg_details) + 1)) );
msg_details.MSG_DATA->length = strlen(ptr_msg_details);
strcpy((char *)msg_details.MSG_DATA->data,(char *)ptr_msg_details);
Im freeing up the memory as
free(ptr_msg_details);
Please suggest me any improvements in memory allocations if any
Thanks
Amit