免费双重免费或腐败错误

double free or corruption error on free

这是我用来在堆上创建 char 数组的代码

int currentArraySize = 10;
char **finalArray = malloc(sizeof(char*)*currentArraySize);
char buf[6] = "hello";
for(int b=0; b<currentArraySize; b++ )
{
    char * tmpString = (char*)malloc(sizeof(char)*6);
    //copy the contents of buf to newly allocated space tmpString
    strncpy(tmpString,buf,6);
    finalArray[b] = tmpString;
}

//this should be a deep copy of finalArray
char **copyArray = malloc(sizeof(char*)*currentArraySize);
for(int c=0; c<currentArraySize; c++)
{
    copyArray[c] = (char*)malloc(sizeof(char*)*6);
    //this supposed to copy the contents of finalArray[c] to copyArray[c] right?
    memcpy(copyArray[c], finalArray[c], sizeof(char)*currentArraySize);
}

当我尝试使用

释放它时
for(int c = 0; c< currentArraySize; c++)
    free(finalArray[c]); //this gives me invalid ptr error
free(finalArray);

没有 memcpy 部分,一切正常,但我使用 memcpy 以某种方式破坏了内存。我是 c 的新手,我无法理解问题的根源

memcpy(copyArray[c], finalArray[c], sizeof(char)*currentArraySize);

最后一个参数最多为sizeof(char)*6