]> git.tdb.fi Git - gldbg.git/commitdiff
Fix several problems reported by valgrind
authorMikko Rasa <tdb@tdb.fi>
Sat, 25 Aug 2012 17:25:42 +0000 (20:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 25 Aug 2012 17:32:06 +0000 (20:32 +0300)
Initialize sock_fd in constructor

Add destructors to free allocated memory

Don't call exit() so the destructors actually get executed

12 files changed:
flavors/gl/source/bufferstate.cpp
flavors/gl/source/bufferstate.h
flavors/gl/source/inspector.cpp
flavors/gl/source/inspector.h
flavors/gl/source/profiler.cpp
flavors/gl/source/profiler.h
source/commandinterpreter.cpp
source/commandinterpreter.h
source/gldbg.cpp
source/gldbg.h
source/grabber.cpp
source/grabber.h

index e48d221df6458375335dd7a29e9c2f81d1e72550..467fb932b0c4573951b3bcc7d2893b54b046c4c7 100644 (file)
@@ -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;
index 18013a77dfb29445ee20271ada9543eaa6ca42f0..6cff3feaf55d2f8f20d85cbd1211c9cbd27d3926 100644 (file)
@@ -27,6 +27,7 @@ struct BufferContent
        std::vector<Array> 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;
index b6456ce7ec1afcfabf52e8b995bb2840cde1e38d..6ff3f7033fa86180b2317f85f2e2d6a443f5800b 100644 (file)
@@ -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)
index 3088a75d39590e0aa39e68db76b54a087baa4f5e..15135297c32328bb29a5d9e1b33d58e5655c9147 100644 (file)
@@ -14,6 +14,7 @@ private:
 
 public:
        Inspector(GlDbg &);
+       ~Inspector();
 
        virtual void decode(const char *, unsigned);
        virtual void process_started();
index 3eb78f2d1efcf725cf7935582bd5dc13cff7edad..94496023ecf1f52178fa655f92a7b9a45774cf8e 100644 (file)
@@ -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)
index cd4af7d09d8bcddbd5e1ec401fe64771d150553b..7605fbcadc8e74fbf1e7067dea56a33926d6968f 100644 (file)
@@ -19,6 +19,7 @@ private:
 
 public:
        Profiler(GlDbg &);
+       ~Profiler();
 
        virtual void decode(const char *, unsigned);
 private:
index d3db5a49412ad8b19f01b55702b9fbf19f0cd898..b8a10a99d03cb0f30a4048c4754f370d42f09f8b 100644 (file)
@@ -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(' ');
index fa881c6883be885b6e2cc03974448e68783766fd..ca5060b4d50f42e4757cadc0f40cf12d5a49f5ad 100644 (file)
@@ -64,6 +64,7 @@ private:
 
 public:
        CommandInterpreter(GlDbg &);
+       ~CommandInterpreter();
 
        template<typename T>
        Command &register_command(const std::string &n, T *o, void (T::*f)(const std::string &))
index 4bc169fcd0079abb2f99811a87db777266e4e86f..c13d5cc2fa6bbafb1b42c87b38139cf78fd58c10 100644 (file)
@@ -20,8 +20,10 @@ using namespace std;
 GlDbg *GlDbg::instance = 0;
 
 GlDbg::GlDbg(int argc, char **argv):
+       done(false),
        cmd_interp(*this),
        process(vector<string>(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;
        }
 }
 
index 3a2bcd1a718535fdba44b00f6d2018f423df74a3..9f77430e753ec54f13f31b7d504cd14831086dbb 100644 (file)
@@ -30,6 +30,7 @@ private:
 
        typedef std::list<Breakpoint> BreakList;
 
+       bool done;
        CommandInterpreter cmd_interp;
        Process process;
        int sock_fd;
index 746cffa876d488ba130abb1c4080004d4dfcf62a..c7f34ab92d8e002c59d66cca1bd45cc33b410b9a 100644 (file)
@@ -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);
index 370108dda0b80f0d303b95bae9a7f51ccada3e87..f92b15596da34949980dc0a55f8824216f2b21b6 100644 (file)
@@ -20,6 +20,7 @@ private:
 
 public:
        Grabber(GlDbg &);
+       ~Grabber();
 private:
        void flavor_init();