Author: mike
Date: 2007-12-15 08:08:23 -0800 (Sat, 15 Dec 2007)
New Revision: 5991
Log:
Fl_Help_View did not release the images it used (STR #1817)



Modified:
   branches/branch-1.1/CHANGES
   branches/branch-1.1/FL/Fl_Help_View.H
   branches/branch-1.1/src/Fl_Help_View.cxx

Modified: branches/branch-1.1/CHANGES
===================================================================
--- branches/branch-1.1/CHANGES 2007-11-28 19:42:30 UTC (rev 5990)
+++ branches/branch-1.1/CHANGES 2007-12-15 16:08:23 UTC (rev 5991)
@@ -4,6 +4,8 @@
          STR #1457, STR #1458, STR #1460, STR #1481, STR #1578,
          STR #1639, STR #1645, STR #1644, STR #1792, STR #1793,
          STR #1742, STR #1777, STR #1794)
+       - Fl_Help_View did not release the images it used (STR
+         #1817)
        - Shared libraries would not build on 64-bit Linux
          systems with an existing non-PIC FLTK installation
          (STR #1791)

Modified: branches/branch-1.1/FL/Fl_Help_View.H
===================================================================
--- branches/branch-1.1/FL/Fl_Help_View.H       2007-11-28 19:42:30 UTC (rev 
5990)
+++ branches/branch-1.1/FL/Fl_Help_View.H       2007-12-15 16:08:23 UTC (rev 
5991)
@@ -156,6 +156,7 @@
   void         draw();
   void         format();
   void         format_table(int *table_width, int *columns, const char *table);
+  void         free_data();
   int          get_align(const char *p, int a);
   const char   *get_attr(const char *p, const char *n, char *buf, int bufsize);
   Fl_Color     get_color(const char *n, Fl_Color c);

Modified: branches/branch-1.1/src/Fl_Help_View.cxx
===================================================================
--- branches/branch-1.1/src/Fl_Help_View.cxx    2007-11-28 19:42:30 UTC (rev 
5990)
+++ branches/branch-1.1/src/Fl_Help_View.cxx    2007-12-15 16:08:23 UTC (rev 
5991)
@@ -36,6 +36,7 @@
 //   Fl_Help_View::draw()            - Draw the Fl_Help_View widget.
 //   Fl_Help_View::format()          - Format the help text.
 //   Fl_Help_View::format_table()    - Format a table...
+//   Fl_Help_View::free_data()       - Free memory used for the document.
 //   Fl_Help_View::get_align()       - Get an alignment attribute.
 //   Fl_Help_View::get_attr()        - Get an attribute value from the string.
 //   Fl_Help_View::get_color()       - Get an alignment attribute.
@@ -888,9 +889,11 @@
              hh = 0;
            }
 
-           if (img) 
+           if (img) {
              img->draw(xx + x() - leftline_,
                        yy + y() - fl_height() + fl_descent() + 2);
+             img->release();
+           }
 
            xx += ww;
            if ((height + 2) > hh)
@@ -2297,6 +2300,111 @@
 
 
 //
+// 'Fl_Help_View::free_data()' - Free memory used for the document.
+//
+
+void
+Fl_Help_View::free_data() {
+  // Releae all images...
+  if (value_) {
+    const char *ptr,           // Pointer into block
+               *attrs;         // Pointer to start of element attributes
+    char       *s,             // Pointer into buffer
+               buf[1024],      // Text buffer
+               attr[1024],     // Attribute buffer
+               wattr[1024],    // Width attribute buffer
+               hattr[1024];    // Height attribute buffer
+
+
+    for (ptr = value_; *ptr;)
+    {
+      if (*ptr == '<')
+      {
+       ptr ++;
+
+        if (strncmp(ptr, "!--", 3) == 0)
+       {
+         // Comment...
+         ptr += 3;
+         if ((ptr = strstr(ptr, "-->")) != NULL)
+         {
+           ptr += 3;
+           continue;
+         }
+         else
+           break;
+       }
+
+        s = buf;
+
+       while (*ptr && *ptr != '>' && !isspace((*ptr)&255))
+          if (s < (buf + sizeof(buf) - 1))
+            *s++ = *ptr++;
+         else
+           ptr ++;
+
+       *s = '\0';
+
+       attrs = ptr;
+       while (*ptr && *ptr != '>')
+          ptr ++;
+
+       if (*ptr == '>')
+          ptr ++;
+
+       if (strcasecmp(buf, "IMG") == 0)
+       {
+         Fl_Shared_Image       *img;
+         int           width;
+         int           height;
+
+
+          get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
+          get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
+         width  = get_length(wattr);
+         height = get_length(hattr);
+
+         if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
+           // Release the image twice to free it from memory...
+           img = get_image(attr, width, height);
+           img->release();
+           img->release();
+         }
+       }
+      }
+    }
+
+    free((void *)value_);
+    value_ = 0;
+  }
+
+  // Free all of the arrays...
+  if (nblocks_) {
+    free(blocks_);
+
+    ablocks_ = 0;
+    nblocks_ = 0;
+    blocks_  = 0;
+  }
+
+  if (nlinks_) {
+    free(links_);
+
+    alinks_ = 0;
+    nlinks_ = 0;
+    links_  = 0;
+  }
+
+  if (ntargets_) {
+    free(targets_);
+
+    atargets_ = 0;
+    ntargets_ = 0;
+    targets_  = 0;
+  }
+}
+
+//
 // 'Fl_Help_View::get_align()' - Get an alignment attribute.
 //
 
@@ -2949,14 +3057,8 @@
 
 Fl_Help_View::~Fl_Help_View()
 {
-  if (nblocks_)
-    free(blocks_);
-  if (nlinks_)
-    free(links_);
-  if (ntargets_)
-    free(targets_);
-  if (value_)
-    free((void *)value_);
+  clear_selection();
+  free_data();
 }
 
 
@@ -3167,18 +3269,16 @@
 Fl_Help_View::value(const char *v)     // I - Text to view
 {
   clear_selection();
+  free_data();
+  set_changed();
 
   if (!v)
     return;
 
-  if (value_ != NULL)
-    free((void *)value_);
-
   value_ = strdup(v);
 
   format();
 
-  set_changed();
   topline(0);
   leftline(0);
 }

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to