~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Monty Taylor
  • Date: 2010-06-20 19:25:46 UTC
  • mto: (1626.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1633.
  • Revision ID: mordred@inaugust.com-20100620192546-vb496u81mnxepu9u
Replaced terrible casting with strdup+free.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
static bool enabled= false;
33
33
static bool debug_enabled= false;
34
 
static char* username= (char *)"";
35
 
static char* password= (char *)"";
36
 
static char* db= (char *)"";
 
34
static char* username= NULL;
 
35
static char* password= NULL;
 
36
static char* db= NULL;
37
37
 
38
38
 
39
39
class ClientConsole: public plugin::Client
271
271
  int pipe_fds[2];
272
272
 
273
273
public:
274
 
  ListenConsole(std::string name_arg)
275
 
    : plugin::Listen(name_arg)
 
274
  ListenConsole(const std::string &name_arg) :
 
275
    plugin::Listen(name_arg)
276
276
  {
277
277
    pipe_fds[0]= -1;
278
278
  }
284
284
      close(pipe_fds[0]);
285
285
      close(pipe_fds[1]);
286
286
    }
 
287
 
 
288
    /* Cleanup from the module strdup'ing these below */
 
289
    free(username);
 
290
    free(password);
 
291
    free(db);
287
292
  }
288
293
 
289
294
  virtual bool getFileDescriptors(std::vector<int> &fds)
313
318
  }
314
319
};
315
320
 
316
 
static ListenConsole *listen_obj= NULL;
317
 
 
318
321
static int init(drizzled::module::Context &context)
319
322
{
320
323
  const module::option_map &vm= context.getOptions();
321
 
  /* the casting here is TERRIBLE, but required for now. We need these vars
322
 
     to be global static char* instances, and we have nowhere to free the
323
 
     memory we might allocate if we were to new them right here. */
 
324
  /* duplicating these here means they need to be freed. They're global, so
 
325
     we'll just have the ListenConsole object do it in its destructor */
324
326
  if (vm.count("username"))
325
 
    username= const_cast<char *>(vm["username"].as<string>().c_str());
 
327
    username= strdup(vm["username"].as<string>().c_str());
 
328
  else
 
329
    username= strdup("");
 
330
 
326
331
  if (vm.count("password"))
327
 
    password= const_cast<char *>(vm["password"].as<string>().c_str());
 
332
    password= strdup(vm["password"].as<string>().c_str());
 
333
  else
 
334
    password= strdup("");
 
335
 
328
336
  if (vm.count("db"))
329
 
    db= const_cast<char *>(vm["db"].as<string>().c_str());
 
337
    db= strdup(vm["db"].as<string>().c_str());
 
338
  else
 
339
    db= strdup("");
330
340
 
331
 
  listen_obj= new ListenConsole("console");
332
 
  context.add(listen_obj);
 
341
  context.add(new ListenConsole("console"));
333
342
  return 0;
334
343
}
335
344