diff --git a/sql/sql_class.h b/sql/sql_class.h
index 0e33a77..8d260d0 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -4682,7 +4682,7 @@ class THD :public Statement,
   bool rename_temporary_table(TABLE *table, const LEX_CSTRING *db,
                               const LEX_CSTRING *table_name);
   bool drop_temporary_table(TABLE *table, bool *is_trans, bool delete_table);
-  bool rm_temporary_table(handlerton *hton, const char *path);
+  bool rm_temporary_table(TABLE_SHARE *share);
   void mark_tmp_tables_as_free_for_reuse();
   void mark_tmp_table_as_free_for_reuse(TABLE *table);

diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 5609ed4..aea49a4 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -4965,10 +4965,7 @@ int create_table_impl(THD *thd,
                                                  false);

     if (!table)
-    {
-      (void) thd->rm_temporary_table(create_info->db_type, path);
       goto err;
-    }

     if (is_trans != NULL)
       *is_trans= table->file->has_transactions();
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index 1c8af5e..29875af 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -659,14 +659,12 @@ bool THD::drop_temporary_table(TABLE *table,
 /**
   Delete the temporary table files.

-  @param base [IN]                    Handlerton for table to be deleted.
-  @param path [IN]                    Path to the table to be deleted (i.e. path
-                                      to its .frm without an extension).
+  @param share [IN]                    TABLE_SHARE for table to be deleted

   @return false                       Success
           true                        Error
 */
-bool THD::rm_temporary_table(handlerton *base, const char *path)
+bool THD::rm_temporary_table(TABLE_SHARE *share)
 {
   DBUG_ENTER("THD::rm_temporary_table");

@@ -674,17 +672,17 @@ bool THD::rm_temporary_table(handlerton *base, const char *path)
   handler *file;
   char frm_path[FN_REFLEN + 1];

-  strxnmov(frm_path, sizeof(frm_path) - 1, path, reg_ext, NullS);
+  strxnmov(frm_path, sizeof(frm_path) - 1, share->path.str, reg_ext, NullS);
   if (mysql_file_delete(key_file_frm, frm_path, MYF(0)))
   {
     error= true;
   }
-  file= get_new_handler((TABLE_SHARE*) 0, current_thd->mem_root, base);
-  if (file && file->ha_delete_table(path))
+  file= get_new_handler(share, current_thd->mem_root, share->db_type());
+  if (file && file->ha_delete_table(share->path.str))
   {
     error= true;
     sql_print_warning("Could not remove temporary table: '%s', error: %d",
-                      path, my_errno);
+                      share->path.str, my_errno);
   }

   delete file;
@@ -1377,7 +1375,7 @@ bool THD::log_events_and_free_tmp_shares()
         */
         append_identifier(this, &s_query, &share->table_name);
         s_query.append(',');
-        rm_temporary_table(share->db_type(), share->path.str);
+        rm_temporary_table(share);
         free_table_share(share);
         my_free(share);
       }
@@ -1454,7 +1452,7 @@ void THD::free_tmp_table_share(TMP_TABLE_SHARE *share,

   if (delete_table)
   {
-    rm_temporary_table(share->db_type(), share->path.str);
+    rm_temporary_table(share);
   }
   free_table_share(share);
   my_free(share);