On Thu, Nov 05, 2009 at 11:02:07AM -0500, Jay Pipes wrote:
> A valiant effort, but I fear there is a major memory leak inherent
> in the new create_internal_temporary_table() function.
> 
> The create_internal_temporary_table() function returns a pointer to
> a Table object.  However, this is the code which allocates memory
> for the Table to be returned:
> 
> >+  if (!(new_tmp_table= (Table*) malloc(sizeof(*new_tmp_table) + 
> >sizeof(*share) +
> >+                                   path_length + 1 + key_length)))
> >+    return NULL;
> 
> The new_tmp_table pointer is later returned to the caller:
> 
> >+  return new_tmp_table;
> 
> IMHO, this is a recipe for disaster since the caller of
> create_internal_temporary_table() must somehow know that the memory
> pointed to by the returned new_tmp_table pointer is actually larger
> than the storage of a Table object -- it is instead allocation for
> the Table, the TableShare, the cache key, and the "path" to the
> table.

This is the ass that is currently hidden somewhere in the whole
mess... but needs some clean up and double checking of what the heck
is going on.

In these areas of code... there be giant scary dragons.

> How is the freeing of this additional memory handled?
> 
> In addition, can someone explain to me the need for something called
> an "internal temporary table"?  Why is this different from a regular
> temporary table?  Couldn't a regular temporary table be used and
> simply be marked hidden from the user?

They don't have real table names :)

They're also generally not added to any list of temp tables. Just used
in a bit of code to execute the query.

They're also not stored in datadir, they're in temp dir.

so they don't have a database.

they have a "database" of the temporary directory... and a "table
name" that's constructed.

so you don't get "test/t1" or "test/#sql-1234", you get
"/tmp/#sql-1243" or "/home/stewart/drizzle/working/var/tmp/#sql-11234"
as the path.
-- 
Stewart Smith

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to