summaryrefslogtreecommitdiff
path: root/sql/sp_head.h
diff options
context:
space:
mode:
authorpem@mysql.com <>2003-06-29 18:15:17 +0200
committerpem@mysql.com <>2003-06-29 18:15:17 +0200
commit9f14ae75161d9ec6d7efb9bbade21a1a36cd2099 (patch)
tree7360f70fae56da177b22e9786c19591c894f7f94 /sql/sp_head.h
parent541c94fcf1f95e22aef9cff615ebe3c2594f0a0a (diff)
downloadmariadb-git-9f14ae75161d9ec6d7efb9bbade21a1a36cd2099.tar.gz
sp_head now has its own mem_root (WL#961).
Also fixed some difficult memory leaks that became apparent in this task.
Diffstat (limited to 'sql/sp_head.h')
-rw-r--r--sql/sp_head.h41
1 files changed, 36 insertions, 5 deletions
diff --git a/sql/sp_head.h b/sql/sp_head.h
index f25e141cd18..dc27da5c5b2 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -54,11 +54,19 @@ public:
List<char *> m_tables; // Used tables.
#endif
+ static void *
+ operator new(size_t size);
+
+ static void
+ operator delete(void *ptr, size_t size);
+
sp_head(LEX_STRING *name, LEX *lex, LEX_STRING *comment, char suid);
int
create(THD *thd);
+ virtual ~sp_head();
+
// Free memory
void
destroy();
@@ -87,6 +95,7 @@ public:
// Restores lex in 'thd' from our copy, but keeps some status from the
// one in 'thd', like ptr, tables, fields, etc.
+ // If 'delete_lex' is true, we delete the current lex.
void
restore_lex(THD *thd);
@@ -122,10 +131,33 @@ public:
m_comment.length= commentlen;
m_comment.str= comment;
m_suid= suid;
- }
+ }
+
+ inline void reset_thd_mem_root(THD *thd)
+ {
+ m_thd_root= thd->mem_root;
+ thd->mem_root= m_mem_root;
+ m_free_list= thd->free_list; // Keep the old list
+ thd->free_list= NULL; // Start a new one
+ m_thd= thd;
+ }
+
+ inline void restore_thd_mem_root(THD *thd)
+ {
+ Item *flist= m_free_list; // The old list
+ m_free_list= thd->free_list; // Get the new one
+ thd->free_list= flist; // Restore the old one
+ m_mem_root= thd->mem_root;
+ thd->mem_root= m_thd_root;
+ m_thd= NULL;
+ }
private:
+ MEM_ROOT m_mem_root; // My own mem_root
+ MEM_ROOT m_thd_root; // Temp. store for thd's mem_root
+ Item *m_free_list; // Where the items go
+ THD *m_thd; // Set if we have reset mem_root
LEX_STRING m_name;
LEX_STRING m_defstr;
LEX_STRING m_comment;
@@ -136,7 +168,7 @@ private:
bool m_suid;
sp_pcontext *m_pcont; // Parse context
- LEX *m_lex; // Temp. store for the other lex
+ List<LEX> m_lex; // Temp. store for the other lex
DYNAMIC_ARRAY m_instr; // The "instructions"
typedef struct
{
@@ -211,11 +243,10 @@ class sp_instr_stmt : public sp_instr
public:
sp_instr_stmt(uint ip)
- : sp_instr(ip)
+ : sp_instr(ip), m_lex(NULL)
{}
- virtual ~sp_instr_stmt()
- {}
+ virtual ~sp_instr_stmt();
virtual int execute(THD *thd, uint *nextp);