Skip to content

Commit

Permalink
MDEV-11602 InnoDB leaks foreign key metadata on DDL operations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Dec 19, 2016
1 parent eb4f2e0 commit 9f863a1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions storage/innobase/dict/dict0dict.cc
Expand Up @@ -1614,6 +1614,7 @@ struct dict_foreign_remove_partial
if (table != NULL) {
table->referenced_set.erase(foreign);
}
dict_foreign_free(foreign);
}
};

Expand Down Expand Up @@ -3535,8 +3536,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;
}
Expand Down Expand Up @@ -3564,7 +3564,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);
Expand Down Expand Up @@ -3620,7 +3620,7 @@ dict_foreign_add_to_cache(
be one */
}

mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
}

return(DB_CANNOT_ADD_CONSTRAINT);
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/dict/dict0load.cc
Expand Up @@ -489,7 +489,7 @@ dict_process_sys_foreign_rec(
}

/* This recieves 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);
Expand Down
8 changes: 4 additions & 4 deletions storage/xtradb/dict/dict0dict.cc
Expand Up @@ -1614,6 +1614,7 @@ struct dict_foreign_remove_partial
if (table != NULL) {
table->referenced_set.erase(foreign);
}
dict_foreign_free(foreign);
}
};

Expand Down Expand Up @@ -3539,8 +3540,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;
}
Expand All @@ -3564,7 +3564,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);
Expand Down Expand Up @@ -3620,7 +3620,7 @@ dict_foreign_add_to_cache(
be one */
}

mem_heap_free(foreign->heap);
dict_foreign_free(foreign);
}

return(DB_CANNOT_ADD_CONSTRAINT);
Expand Down
2 changes: 1 addition & 1 deletion storage/xtradb/dict/dict0load.cc
Expand Up @@ -491,7 +491,7 @@ dict_process_sys_foreign_rec(
}

/* This recieves 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);
Expand Down

0 comments on commit 9f863a1

Please sign in to comment.