FLTK logo

[master] 817a97b - Fluid: Fix variable naming and a memory leak

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 817a97b - Fluid: Fix variable naming and a memory leak "Matthias Melcher" Nov 23, 2022  
 
commit 817a97bb65883b0ffdbcf9a8eb5b4431cd8a4331
Author:     Matthias Melcher <github@matthiasm.com>
AuthorDate: Wed Nov 23 15:17:54 2022 +0100
Commit:     Matthias Melcher <github@matthiasm.com>
CommitDate: Wed Nov 23 15:18:01 2022 +0100

    Fluid: Fix variable naming and a memory leak

 fluid/CodeEditor.cxx     | 14 +++++++++++---
 fluid/CodeEditor.h       |  5 +++--
 fluid/fluid.cxx          | 10 ++++++----
 fluid/function_panel.cxx | 38 +++++++++++++++++++-------------------
 fluid/function_panel.fl  |  8 ++++----
 fluid/function_panel.h   |  4 ++--
 6 files changed, 45 insertions(+), 34 deletions(-)

diff --git fluid/CodeEditor.cxx fluid/CodeEditor.cxx
index ec8afd7..eea99d2 100644
--- fluid/CodeEditor.cxx
+++ fluid/CodeEditor.cxx
@@ -295,16 +295,24 @@ void CodeViewer::draw()
   Fl::set_color(FL_SELECTION_COLOR, c);
 }
 
-// ---- DesignViewer implementation
+// ---- TextViewer implementation
 
 /**
- Create a DesignViewer widget.
+ Create a TextViewer widget.
  \param[in] X, Y, W, H position and size of the widget
  \param[in] L optional label
  */
-DesignViewer::DesignViewer(int X, int Y, int W, int H, const char *L)
+TextViewer::TextViewer(int X, int Y, int W, int H, const char *L)
 : Fl_Text_Display(X, Y, W, H, L)
 {
   buffer(new Fl_Text_Buffer);
 }
 
+/**
+ Avoid memory leaks.
+ */
+TextViewer::~TextViewer() {
+  Fl_Text_Buffer *buf = mBuffer;
+  buffer(0);
+  delete buf;
+}
diff --git fluid/CodeEditor.h fluid/CodeEditor.h
index 767c960..e55bff8 100644
--- fluid/CodeEditor.h
+++ fluid/CodeEditor.h
@@ -68,9 +68,10 @@ protected:
 
 // ---- DesignViewer declaration
 
-class DesignViewer : public Fl_Text_Display {
+class TextViewer : public Fl_Text_Display {
 public:
-  DesignViewer(int X, int Y, int W, int H, const char *L=0);
+  TextViewer(int X, int Y, int W, int H, const char *L=0);
+  ~TextViewer();
   int top_line() { return get_absolute_top_line_number(); }
 };
 
diff --git fluid/fluid.cxx fluid/fluid.cxx
index 252353b..ea87448 100644
--- fluid/fluid.cxx
+++ fluid/fluid.cxx
@@ -1794,11 +1794,11 @@ void update_sourceview_cb(Fl_Button*, void*)
     strlcat(sv_design_filename, "source_view_tmp.fl", FL_PATH_MAX);
   }
 
-  if (sv_design->visible_r()) {
+  if (sv_project->visible_r()) {
     write_file(sv_design_filename);
-    int top = sv_design->top_line();
-    sv_design->buffer()->loadfile(sv_design_filename);
-    sv_design->scroll(top, 0);
+    int top = sv_project->top_line();
+    sv_project->buffer()->loadfile(sv_design_filename);
+    sv_project->scroll(top, 0);
   } else if (sv_strings->visible_r()) {
     static const char *exts[] = { ".txt", ".po", ".msg" };
     char fn[FL_PATH_MAX];
@@ -2021,6 +2021,8 @@ int main(int argc,char **argv) {
 #endif // _WIN32
 
   undo_clear();
+  if (g_shell_command)
+    ::free(g_shell_command);
 
   return (0);
 }
diff --git fluid/function_panel.cxx fluid/function_panel.cxx
index 3315740..26e2a70 100644
--- fluid/function_panel.cxx
+++ fluid/function_panel.cxx
@@ -1484,9 +1484,9 @@ CodeViewer *sv_source=(CodeViewer *)0;
 
 CodeViewer *sv_header=(CodeViewer *)0;
 
-DesignViewer *sv_strings=(DesignViewer *)0;
+TextViewer *sv_strings=(TextViewer *)0;
 
-DesignViewer *sv_design=(DesignViewer *)0;
+TextViewer *sv_project=(TextViewer *)0;
 
 Fl_Light_Button *sv_autorefresh=(Fl_Light_Button *)0;
 
@@ -1545,7 +1545,7 @@ Fl_Double_Window* make_sourceview() {
       { Fl_Group* o = new Fl_Group(10, 35, 500, 415, "Strings");
         o->labelsize(13);
         o->hide();
-        { DesignViewer* o = sv_strings = new DesignViewer(20, 50, 480, 390);
+        { TextViewer* o = sv_strings = new TextViewer(20, 50, 480, 390);
           sv_strings->box(FL_DOWN_FRAME);
           sv_strings->color(FL_BACKGROUND2_COLOR);
           sv_strings->selection_color(FL_SELECTION_COLOR);
@@ -1560,28 +1560,28 @@ Fl_Double_Window* make_sourceview() {
           Fl_Group::current()->resizable(sv_strings);
           o->linenumber_width(60);
           o->linenumber_size(o->Fl_Text_Display::textsize());
-        } // DesignViewer* sv_strings
+        } // TextViewer* sv_strings
         o->end();
       } // Fl_Group* o
-      { Fl_Group* o = new Fl_Group(10, 35, 500, 415, "Design");
+      { Fl_Group* o = new Fl_Group(10, 35, 500, 415, "Project");
         o->labelsize(13);
         o->hide();
-        { DesignViewer* o = sv_design = new DesignViewer(20, 50, 480, 390);
-          sv_design->box(FL_DOWN_FRAME);
-          sv_design->color(FL_BACKGROUND2_COLOR);
-          sv_design->selection_color(FL_SELECTION_COLOR);
-          sv_design->labeltype(FL_NORMAL_LABEL);
-          sv_design->labelfont(0);
-          sv_design->labelsize(14);
-          sv_design->labelcolor(FL_FOREGROUND_COLOR);
-          sv_design->textfont(4);
-          sv_design->textsize(11);
-          sv_design->align(Fl_Align(FL_ALIGN_TOP));
-          sv_design->when(FL_WHEN_RELEASE);
-          Fl_Group::current()->resizable(sv_design);
+        { TextViewer* o = sv_project = new TextViewer(20, 50, 480, 390);
+          sv_project->box(FL_DOWN_FRAME);
+          sv_project->color(FL_BACKGROUND2_COLOR);
+          sv_project->selection_color(FL_SELECTION_COLOR);
+          sv_project->labeltype(FL_NORMAL_LABEL);
+          sv_project->labelfont(0);
+          sv_project->labelsize(14);
+          sv_project->labelcolor(FL_FOREGROUND_COLOR);
+          sv_project->textfont(4);
+          sv_project->textsize(11);
+          sv_project->align(Fl_Align(FL_ALIGN_TOP));
+          sv_project->when(FL_WHEN_RELEASE);
+          Fl_Group::current()->resizable(sv_project);
           o->linenumber_width(60);
           o->linenumber_size(o->Fl_Text_Display::textsize());
-        } // DesignViewer* sv_design
+        } // TextViewer* sv_project
         o->end();
       } // Fl_Group* o
       sv_tab->end();
diff --git fluid/function_panel.fl fluid/function_panel.fl
index 6631035..e1464fd 100644
--- fluid/function_panel.fl
+++ fluid/function_panel.fl
@@ -1017,18 +1017,18 @@ Function {make_sourceview()} {open
           xywh {20 50 480 390} textfont 4 textsize 11 resizable
           code1 {o->linenumber_width(60);}
           code2 {o->linenumber_size(o->Fl_Text_Display::textsize());}
-          class DesignViewer
+          class TextViewer
         }
       }
       Fl_Group {} {
-        label Design open
+        label Project open
         xywh {10 35 500 415} labelsize 13 hide
       } {
-        Fl_Text_Display sv_design {
+        Fl_Text_Display sv_project {
           xywh {20 50 480 390} textfont 4 textsize 11 resizable
           code1 {o->linenumber_width(60);}
           code2 {o->linenumber_size(o->Fl_Text_Display::textsize());}
-          class DesignViewer
+          class TextViewer
         }
       }
     }
diff --git fluid/function_panel.h fluid/function_panel.h
index d94e02d..b64c1b9 100644
--- fluid/function_panel.h
+++ fluid/function_panel.h
@@ -114,8 +114,8 @@ extern void update_sourceview_position_cb(Fl_Tabs*, void*);
 extern Fl_Tabs *sv_tab;
 extern CodeViewer *sv_source;
 extern CodeViewer *sv_header;
-extern DesignViewer *sv_strings;
-extern DesignViewer *sv_design;
+extern TextViewer *sv_strings;
+extern TextViewer *sv_project;
 extern void update_sourceview_cb(Fl_Button*, void*);
 extern Fl_Light_Button *sv_autorefresh;
 extern Fl_Light_Button *sv_autoposition;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.