~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/charset.cc

  • Committer: Brian Aker
  • Date: 2009-08-03 06:08:05 UTC
  • mfrom: (1106.1.5 memory-fix)
  • Revision ID: brian@gaz-20090803060805-fqaa2t3jejgwhwu2
Collection of Valgrind fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include <mystrings/m_ctype.h>
19
19
#include <mystrings/m_string.h>
20
20
#include <drizzled/configmake.h>
21
 
 
 
21
#include <vector>
 
22
 
 
23
using namespace std;
 
24
 
 
25
 
 
26
/*
 
27
  We collect memory in this vector that we free on delete.
 
28
*/
 
29
static vector<void *>memory_vector;
22
30
 
23
31
/*
24
32
  The code below implements this functionality:
58
66
  unsigned char *state_map;
59
67
  unsigned char *ident_map;
60
68
 
61
 
  if (!(cs->state_map= (unsigned char*) malloc(256)))
 
69
  if (!(cs->state_map= (unsigned char*) cs_alloc(256)))
62
70
    return 1;
63
71
    
64
 
  if (!(cs->ident_map= (unsigned char*) malloc(256)))
 
72
  if (!(cs->ident_map= (unsigned char*) cs_alloc(256)))
65
73
    return 1;
66
74
 
67
75
  state_map= cs->state_map;
127
135
 
128
136
void *cs_alloc(size_t size)
129
137
{
130
 
  return malloc(size);
 
138
  void *ptr= malloc(size);
 
139
 
 
140
  memory_vector.push_back(ptr);
 
141
 
 
142
  return ptr;
131
143
}
132
144
 
133
145
 
168
180
void free_charsets(void)
169
181
{
170
182
  charset_initialized= true;
 
183
 
 
184
  while (memory_vector.empty() == false)
 
185
  {
 
186
    void *ptr= memory_vector.back();
 
187
    memory_vector.pop_back();
 
188
    free(ptr);
 
189
  }
 
190
  memory_vector.clear();
 
191
 
171
192
}
172
193
 
173
194