fix invalid read

This commit is contained in:
yihaoDeng 2024-03-18 07:35:33 +00:00
parent 3964f01793
commit 65a1dcc30e
1 changed files with 12 additions and 4 deletions

View File

@ -290,16 +290,24 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
size_t schemaExtSize = hasSchemaExt ? pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt) : 0; size_t schemaExtSize = hasSchemaExt ? pTableMeta->tableInfo.numOfColumns * sizeof(SSchemaExt) : 0;
size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema); size_t size = sizeof(STableMeta) + numOfFields * sizeof(SSchema);
int32_t cpSize = sizeof(STableMeta) - sizeof(void*);
STableMeta* p = taosMemoryMalloc(size + schemaExtSize); STableMeta* p = taosMemoryMalloc(size + schemaExtSize);
if (NULL == p) return NULL; if (NULL == p) return NULL;
memcpy(p, pTableMeta, size); memcpy(p, pTableMeta, cpSize);
if (hasSchemaExt) { if (hasSchemaExt) {
SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size); p->schemaExt = (SSchemaExt*)(((char*)p) + size);
p->schemaExt = pSchemaExt; } else {
memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize); p->schemaExt = NULL;
} }
memcpy(p->schema, pTableMeta->schema, numOfFields * sizeof(SSchema));
// p->schemaExt = NULL;
// if (hasSchemaExt) {
// SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)p + size);
// p->schemaExt = pSchemaExt;
// memcpy(pSchemaExt, pTableMeta->schemaExt, schemaExtSize);
// }
return p; return p;
} }