I have created a structure:
struct SeqInfo
{ int Len;
int uncLen;
int *uncIndex;
char *seq;
char *seqc;
char *seqr;};
I malloc space and initialize a structure in the function:
void initSeqInfo(struct SeqInfo *SI, char *seq, char *seqc, char *seqr){
int lenTemp;
int lenUnc;
// length of the seq and uncertain
lenTemp = strlen(seq);
lenUnc = Num_uncertains(seqr);
// make space
SI->seq = (char *)malloc(sizeof(char)*lenTemp);
SI->seqc = (char *)malloc(sizeof(char)*lenTemp);
SI->seqr = (char *)malloc(sizeof(char)*lenTemp);
SI->uncIndex = (int *)malloc(sizeof(int)*lenUnc);
// init seq
SI->Len = lenTemp;
SI->uncLen = lenUnc;
// init index
Index_uncertains(seqr, SI->uncIndex);
// init seq
strcpy(SI->seq, seq);
strcpy(SI->seqc, seqc);
strcpy(SI->seqr, seqr);
}
I also define a function to free the space as follows:
// free space for structure SeqInfo
void freespace(struct SeqInfo SI){
free(SI.seq);
free(SI.seqc);
free(SI.seqr);
free(SI.uncIndex);
}
I define a pointer to the structure and initialize it as follows:
struct SeqInfo *SeqRNAs;
SeqRNAs = (struct SeqInfo*)malloc(sizeof(struct SeqInfo)*NumComb);
initSeqInfo(&SeqRNAs[0], seq10, struct10_con, struct10_req);//A1P2
initSeqInfo(&SeqRNAs[1], seq13, struct13_con, struct13_req);//A3P1
initSeqInfo(&SeqRNAs[2], seq4, struct4_con, struct4_req);//P1P4
initSeqInfo(&SeqRNAs[3], seq14, struct14_con, struct14_req);//A3P2
initSeqInfo(&SeqRNAs[4], seq17, struct17_con, struct17_req);//A4P2
initSeqInfo(&SeqRNAs[5], seq18, struct18_con, struct18_req);//A4P3
The problem occurs when I try to free the space for the defined SeqRNAs[]:
for(i = 0; i < NumComb; i++){
freespace(SeqRNAs[i]);
}
The error is:
*** glibc detected *** ./Blocks14E: free(): invalid next size (fast): 0x0000000001123210 ***
Why am I getting this error? I am pretty sure this is the only place I free the space.