Commit a01bfc9f authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-11602 InnoDB leaks foreign key metadata on DDL operations

Essentially revert MDEV-6759, which addressed a double free of memory
by removing the freeing altogether, introducing the memory leaks.
No double free was observed when running the test suite -DWITH_ASAN.

Replace some mem_heap_free(foreign->heap) with dict_foreign_free(foreign)
so that the calls can be located and instrumented more easily when needed.
parent 8375a2c1
......@@ -1701,6 +1701,7 @@ struct dict_foreign_remove_partial
if (table != NULL) {
table->referenced_set.erase(foreign);
}
dict_foreign_free(foreign);
}
};
......@@ -3759,7 +3760,6 @@ dict_foreign_add_to_cache(
}
if (for_in_cache) {
/* Free the foreign object */
dict_foreign_free(foreign);
} else {
for_in_cache = foreign;
......@@ -3789,10 +3789,9 @@ dict_foreign_add_to_cache(
"referenced table do not match"
" the ones in table.");
if (for_in_cache == foreign) {
mem_heap_free(foreign->heap);
}
if (for_in_cache == foreign) {
dict_foreign_free(foreign);
}
DBUG_RETURN(DB_CANNOT_ADD_CONSTRAINT);
}
......@@ -3846,7 +3845,8 @@ dict_foreign_add_to_cache(
elements removed must
be one */
}
mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
}
DBUG_RETURN(DB_CANNOT_ADD_CONSTRAINT);
......
......@@ -493,7 +493,7 @@ dict_process_sys_foreign_rec(
}
/* This receives a dict_foreign_t* that points to a stack variable.
So mem_heap_free(foreign->heap) is not used as elsewhere.
So dict_foreign_free(foreign) is not used as elsewhere.
Since the heap used here is freed elsewhere, foreign->heap
is not assigned. */
foreign->id = mem_heap_strdupl(heap, (const char*) field, len);
......
......@@ -1643,6 +1643,7 @@ struct dict_foreign_remove_partial
if (table != NULL) {
table->referenced_set.erase(foreign);
}
dict_foreign_free(foreign);
}
};
......@@ -3597,8 +3598,7 @@ dict_foreign_add_to_cache(
}
if (for_in_cache) {
/* Free the foreign object */
mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
} else {
for_in_cache = foreign;
}
......@@ -3622,7 +3622,7 @@ dict_foreign_add_to_cache(
" the ones in table.");
if (for_in_cache == foreign) {
mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
}
return(DB_CANNOT_ADD_CONSTRAINT);
......@@ -3678,7 +3678,7 @@ dict_foreign_add_to_cache(
be one */
}
mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
}
return(DB_CANNOT_ADD_CONSTRAINT);
......
......@@ -490,7 +490,7 @@ dict_process_sys_foreign_rec(
}
/* This receives a dict_foreign_t* that points to a stack variable.
So mem_heap_free(foreign->heap) is not used as elsewhere.
So dict_foreign_free(foreign) is not used as elsewhere.
Since the heap used here is freed elsewhere, foreign->heap
is not assigned. */
foreign->id = mem_heap_strdupl(heap, (const char*) field, len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment