lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lynx-dev dev.10 progress


From: Leonid Pauzner
Subject: Re: lynx-dev dev.10 progress
Date: Wed, 20 Nov 2002 13:43:28 +0300 (MSK)

19-Nov-2002 21:01 Thomas Dickey wrote:

> It's something to do with the pool-allocation.  valgrind is probably showing
> me the problem that I'm looking for, e.g., this (repeated a lot of times):

Still I cannot figure the source of problems with line->date .

Try the attached patch. It reverts changes related to allocation of lines
in pool. Perhaps this will help to isolate the problem since the patch is
relatively small and straight forward. (Allocation of anchors left in pool).

[Also I would like to ask you to add -p flag to diff command
when creating snapshots or patches at lynx.isc.org/current/
so it became more readable with a function names.]


> ==6270== Invalid read of size 1
> ==6270==    at 0x805C0EC: display_line (./GridText.c:1282)
> ==6270==    by 0x805D446: display_page (./GridText.c:2001)
> ==6270==    by 0x8069BF2: HText_pageDisplay (./GridText.c:6820)
> ==6270==    by 0x808656E: mainloop (./LYMainLoop.c:6241)
> ==6270==    by 0x807A28A: main (./LYMain.c:2060)
> ==6270==    by 0x402A6577: (within /lib/libc-2.1.3.so)
> ==6270==    Address 0x4331E80E is 18 bytes inside a block of size 32776 free'd
> ==6270==    at 0x40042630: free (vg_clientfuncs.c:171)
> ==6270==    by 0x805BFE7: HText_free (./GridText.c:1177)
> ==6270==    by 0x806BD94: HTuncache_current_document (./GridText.c:8112)
> ==6270==    by 0x807DCBD: handle_LYK_ACTIVATE (./LYMainLoop.c:1427)
> ==6270==    by 0x8087DBE: mainloop (./LYMainLoop.c:7113)
> ==6270==    by 0x807A28A: main (./LYMain.c:2060)
> ==6270==

> The problem happens with/without color-style.  Since it's probably a memory
> issue, it's not necessarily going to break the same way for everyone.


diff -u -p old/gridtext.c ./gridtext.c
--- old/gridtext.c      Tue Nov 19 11:37:18 2002
+++ ./gridtext.c        Wed Nov 20 13:10:34 2002
@@ -322,6 +322,7 @@ typedef struct _line {


 #define LINE_SIZE(l) (sizeof(HTLine)+(l))      /* Allow for terminator */
+#define allocHTLine(l) (HTLine *)calloc(1, LINE_SIZE(l))

 /* last line buffer, the second is used in split_line(). Not in pool! */
 /* "can't wrap in middle of multibyte sequences, so allocate 2 extra" */
@@ -892,7 +893,7 @@ PUBLIC HText *      HText_new ARGS1(
     if (!self->pool)
        outofmem(__FILE__, "HText_New");

-    line = self->last_line = (HTLine*)tmp_long_line[0];
+    line = self->last_line = allocHTLine(MAX_LINE);
     line->next = line->prev = line;
     line->offset = line->size = 0;
 #ifdef USE_COLOR_STYLE
@@ -1067,6 +1068,23 @@ PUBLIC void HText_free ARGS1(
        return;

     HTAnchor_setDocument(self->node_anchor, (HyperDoc *)0);
+    while (YES) {      /* Free off line array */
+       HTLine * l = self->last_line;
+       if (l) {
+           l->next->prev = l->prev;
+           l->prev->next = l->next;    /* Unlink l */
+           self->last_line = l->prev;
+           if (l != self->last_line) {
+               FREE(l);
+           } else {
+               free(l);
+           }
+       }
+       if (l == self->last_line) {     /* empty */
+           l = self->last_line = NULL;
+           break;
+       }
+    }

     while (self->first_anchor) {               /* Free off anchor array */
        TextAnchor * l = self->first_anchor;
@@ -2488,7 +2506,7 @@ PRIVATE void move_anchors_in_region ARGS
  *  Some necessary changes for anchors starting on this line are also done
  *  here if needed.
  *  Returns a newly allocated HTLine* if changes were made
- *    (lines allocated in pool, caller should not free the old one).
+ *    (caller has to free the old one).
  *  Returns NULL if no changes needed.  (Remove-spaces code may be buggy...)
  * - kw
  */
@@ -2524,18 +2542,15 @@ PRIVATE HTLine * insert_blanks_in_line A
     if (line->size + added_chars > MAX_LINE - 2)
        return NULL;
     if (line == text->last_line)
-       if (line == (HTLine*)tmp_long_line[0])
-          mod_line = (HTLine*)tmp_long_line[1];
-       else
-          mod_line = (HTLine*)tmp_long_line[0];
+       mod_line = allocHTLine(MAX_LINE);
     else
-       POOLallocHTLine(mod_line, line->size + added_chars);
+       mod_line = allocHTLine(line->size + added_chars);
     if (!mod_line)
        return NULL;
     if (!prev_anchor)
        prev_anchor = text->first_anchor;
     head_processed = (prev_anchor && prev_anchor->line_num < line_number);
-    memcpy(mod_line, line, LINE_SIZE(0));
+    memcpy(mod_line, line, LINE_SIZE(1));
     t = newdata = mod_line->data;
     ip = 0;
     while (ip <= ninserts) {
@@ -2636,6 +2651,7 @@ PRIVATE void split_line ARGS2(
        unsigned,       split)
 {
     HTStyle * style = text->style;
+    HTLine * temp;
     int spare;
     int indent = text->in_line_1 ?
          text->style->indent1st : text->style->leftIndent;
@@ -2647,22 +2663,18 @@ PRIVATE void split_line ARGS2(
     int TailTrim = 0;
     int s, s_post, s_pre, t_underline = underline_on, t_bold = bold_on;
     char *p;
+    HTLine * previous = text->last_line;
     int ctrl_chars_on_previous_line = 0;
     int utfxtra_on_previous_line = UTFXTRA_ON_THIS_LINE;
     char * cp;
-
-    HTLine * previous = text->last_line;
-    HTLine * line;
+    /* can't wrap in middle of multibyte sequences, so allocate 2 extra */
+    HTLine * line = (HTLine *)LY_CALLOC(1, LINE_SIZE(MAX_LINE)+2);

     /*
-     *  Set new line.
+     *  Make new line.
      */
-    if (previous == (HTLine*)tmp_long_line[0])
-       line = (HTLine*)tmp_long_line[1];
-    else
-       line = (HTLine*)tmp_long_line[0];
-    memset(line, 0, LINE_SIZE(0));
-
+    if (line == NULL)
+       outofmem(__FILE__, "split_line_1");
     ctrl_chars_on_this_line = 0; /*reset since we are going to a new line*/
     utfxtra_on_this_line = 0;  /*reset too, we'll count them*/
     HText_setLastChar(text, ' ');
@@ -2951,10 +2963,8 @@ PRIVATE void split_line ARGS2(
     }
 #endif /*USE_COLOR_STYLE*/

-    {
-    HTLine* temp;
-    POOLallocHTLine(temp, previous->size);
-    if (!temp)
+    temp = (HTLine *)LY_CALLOC(1, LINE_SIZE(previous->size));
+    if (temp == NULL)
        outofmem(__FILE__, "split_line_2");
     memcpy(temp, previous, LINE_SIZE(previous->size));
 #if defined(USE_COLOR_STYLE)
@@ -2963,8 +2973,8 @@ PRIVATE void split_line ARGS2(
        outofmem(__FILE__, "split_line_2");
     memcpy(temp->styles, previous->styles, 
sizeof(HTStyleChange)*previous->numstyles);
 #endif
+    FREE(previous);
     previous = temp;
-    }

     previous->prev->next = previous;   /* Link in new line */
     previous->next->prev = previous;   /* Could be same node of course */
@@ -3247,6 +3257,8 @@ PRIVATE void split_line ARGS2(
            previous->next->prev = jline;
            previous->prev->next = jline;

+           FREE(previous);
+
            previous = jline;
        }
        { /* (ht_num_runs==1) */
@@ -4498,6 +4510,7 @@ PRIVATE int HText_insertBlanksInStblLine
            lines_changed++;
            if (line == first_line)
                first_line = mod_line;
+           free(line);
            line = mod_line;
 #ifdef DISP_PARTIAL
            /*
@@ -5508,6 +5521,7 @@ PUBLIC void HText_endAppend ARGS1(
         */
        next_to_the_last_line->next = line_ptr;
        line_ptr->prev = next_to_the_last_line;
+       FREE(text->last_line);
        text->last_line = next_to_the_last_line;
        text->Lines--;
        CTRACE((tfp, "GridText: New bottom line: `%s'\n",
@@ -8495,15 +8509,18 @@ PUBLIC void HText_RemovePreviousLine ARG
        HText *,        text)
 {
     HTLine *line, *previous;
+    char *data;

     if (!(text && text->Lines > 1))
        return;

     line = text->last_line->prev;
+    data = line->data;
     previous = line->prev;
     previous->next = text->last_line;
     text->last_line->prev = previous;
     text->Lines--;
+    FREE(line);
 }

 /*
@@ -11692,7 +11709,7 @@ PRIVATE void insert_new_textarea_anchor
      *  Clone and initialize the struct's needed to add a new TEXTAREA
      *  anchor.
      */
-    POOLallocHTLine(l, MAX_LINE);
+    l = allocHTLine(MAX_LINE);
     POOLtypecalloc(TextAnchor, a);
     POOLtypecalloc(FormInfo, f);
     if (a == NULL || l == NULL || f == NULL)
@@ -12516,7 +12533,7 @@ PUBLIC int HText_InsertFile ARGS1(
            break;
     }

-    POOLallocHTLine(l, MAX_LINE);
+    l = allocHTLine(MAX_LINE);
     POOLtypecalloc(TextAnchor, a);
     POOLtypecalloc(FormInfo, f);
     if (a == NULL || l == NULL || f == NULL)



; To UNSUBSCRIBE: Send "unsubscribe lynx-dev" to address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]