From: Mikko Rasa Date: Sat, 25 Aug 2012 17:25:42 +0000 (+0300) Subject: Fix several problems reported by valgrind X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a34325fadec5b2be003bf9af1f081bfc4c83e8b6;p=gldbg.git Fix several problems reported by valgrind Initialize sock_fd in constructor Add destructors to free allocated memory Don't call exit() so the destructors actually get executed --- diff --git a/flavors/gl/source/bufferstate.cpp b/flavors/gl/source/bufferstate.cpp index e48d221..467fb93 100644 --- a/flavors/gl/source/bufferstate.cpp +++ b/flavors/gl/source/bufferstate.cpp @@ -137,6 +137,11 @@ BufferState::BufferState(): data(0) { } +BufferState::~BufferState() +{ + delete[] data; +} + void BufferState::set_data(unsigned sz, const void *ptr, GLenum use) { usage = use; diff --git a/flavors/gl/source/bufferstate.h b/flavors/gl/source/bufferstate.h index 18013a7..6cff3fe 100644 --- a/flavors/gl/source/bufferstate.h +++ b/flavors/gl/source/bufferstate.h @@ -27,6 +27,7 @@ struct BufferContent std::vector arrays; BufferContent(); + void update(const ArrayState &); void update_elements(GLenum); std::string describe() const; @@ -42,6 +43,8 @@ struct BufferState BufferContent content; BufferState(); + ~BufferState(); + void set_data(unsigned, const void *, GLenum); void set_sub_data(unsigned, unsigned, const void *); std::string describe() const; diff --git a/flavors/gl/source/inspector.cpp b/flavors/gl/source/inspector.cpp index b6456ce..6ff3f70 100644 --- a/flavors/gl/source/inspector.cpp +++ b/flavors/gl/source/inspector.cpp @@ -57,6 +57,11 @@ Inspector::Inspector(GlDbg &d): decoder->gldBreak = gldBreak; } +Inspector::~Inspector() +{ + gldecoder_delete(decoder); +} + void Inspector::decode(const char *data, unsigned len) { if(query_state) diff --git a/flavors/gl/source/inspector.h b/flavors/gl/source/inspector.h index 3088a75..1513529 100644 --- a/flavors/gl/source/inspector.h +++ b/flavors/gl/source/inspector.h @@ -14,6 +14,7 @@ private: public: Inspector(GlDbg &); + ~Inspector(); virtual void decode(const char *, unsigned); virtual void process_started(); diff --git a/flavors/gl/source/profiler.cpp b/flavors/gl/source/profiler.cpp index 3eb78f2..9449602 100644 --- a/flavors/gl/source/profiler.cpp +++ b/flavors/gl/source/profiler.cpp @@ -21,6 +21,11 @@ Profiler::Profiler(GlDbg &dbg): decoder->glXSwapBuffers = glXSwapBuffers; } +Profiler::~Profiler() +{ + gldecoder_delete(decoder); +} + void Profiler::decode(const char *data, unsigned len) { if(enabled) diff --git a/flavors/gl/source/profiler.h b/flavors/gl/source/profiler.h index cd4af7d..7605fbc 100644 --- a/flavors/gl/source/profiler.h +++ b/flavors/gl/source/profiler.h @@ -19,6 +19,7 @@ private: public: Profiler(GlDbg &); + ~Profiler(); virtual void decode(const char *, unsigned); private: diff --git a/source/commandinterpreter.cpp b/source/commandinterpreter.cpp index d3db5a4..b8a10a9 100644 --- a/source/commandinterpreter.cpp +++ b/source/commandinterpreter.cpp @@ -53,6 +53,12 @@ CommandInterpreter::CommandInterpreter(GlDbg &d): } +CommandInterpreter::~CommandInterpreter() +{ + for(CommandMap::iterator i=commands.begin(); i!=commands.end(); ++i) + delete i->second; +} + void CommandInterpreter::execute(const string &cmd) { unsigned space = cmd.find(' '); diff --git a/source/commandinterpreter.h b/source/commandinterpreter.h index fa881c6..ca5060b 100644 --- a/source/commandinterpreter.h +++ b/source/commandinterpreter.h @@ -64,6 +64,7 @@ private: public: CommandInterpreter(GlDbg &); + ~CommandInterpreter(); template Command ®ister_command(const std::string &n, T *o, void (T::*f)(const std::string &)) diff --git a/source/gldbg.cpp b/source/gldbg.cpp index 4bc169f..c13d5cc 100644 --- a/source/gldbg.cpp +++ b/source/gldbg.cpp @@ -20,8 +20,10 @@ using namespace std; GlDbg *GlDbg::instance = 0; GlDbg::GlDbg(int argc, char **argv): + done(false), cmd_interp(*this), process(vector(argv+1, argv+argc)), + sock_fd(-1), buf_offset(0), flushing(false), got_sigchld(false), @@ -56,7 +58,7 @@ int GlDbg::main() printf("Copyright © 2009-2010 Mikkosoft Productions\n"); printf("Type \"help\" for a list of commands\n"); - while(1) + while(!done) tick(); return 0; @@ -179,7 +181,7 @@ void GlDbg::quit(bool force) { if(!force && process.get_state()!=Process::INACTIVE) throw runtime_error("Program is still running"); - exit(0); + done = true; } void GlDbg::tick() @@ -225,7 +227,7 @@ void GlDbg::tick() free(line); } else if(pstate==Process::INACTIVE) - exit(0); + done = true; } } diff --git a/source/gldbg.h b/source/gldbg.h index 3a2bcd1..9f77430 100644 --- a/source/gldbg.h +++ b/source/gldbg.h @@ -30,6 +30,7 @@ private: typedef std::list BreakList; + bool done; CommandInterpreter cmd_interp; Process process; int sock_fd; diff --git a/source/grabber.cpp b/source/grabber.cpp index 746cffa..c7f34ab 100644 --- a/source/grabber.cpp +++ b/source/grabber.cpp @@ -39,6 +39,11 @@ Grabber::Grabber(GlDbg &g): flavor_init(); } +Grabber::~Grabber() +{ + gldecoder_delete(decoder); +} + void Grabber::decode(const char *data, unsigned len) { gldecoder_decode(decoder, data, len); diff --git a/source/grabber.h b/source/grabber.h index 370108d..f92b155 100644 --- a/source/grabber.h +++ b/source/grabber.h @@ -20,6 +20,7 @@ private: public: Grabber(GlDbg &); + ~Grabber(); private: void flavor_init();