lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev dev.11 leaks dramatically (allocHTLine)


From: Leonid Pauzner
Subject: lynx-dev dev.11 leaks dramatically (allocHTLine)
Date: Tue, 3 Dec 2002 02:43:05 +0300 (MSK)

Reading a diff between dev9e snapshot and dev11
I found out that the line/pool code is broken:
the last line is always alloced outside the pool and never freed.
In my code the last line was a fixed buffer.
Tom?

Back to my version:


--- gridtext.ori        Mon Dec  2 02:07:38 2002
+++ gridtext.c  Tue Dec  3 02:17:00 2002
@@ -323,7 +315,11 @@ 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" */
+static char tmp_long_line[2][LINE_SIZE(MAX_LINE+2)];  /* (HTLine*) in fact*/
+

 typedef struct _TextAnchor {
        struct _TextAnchor *    next;
@@ -888,9 +884,8 @@ PUBLIC HText *      HText_new ARGS1(
     POOL_NEW(HTPool, self->pool);
     if (!self->pool)
        outofmem(__FILE__, "HText_New");
-    line = self->last_line = allocHTLine(MAX_LINE);
-    if (line == NULL)
-       outofmem(__FILE__, "HText_New");
+
+    line = self->last_line = (HTLine*)tmp_long_line[0];
     line->next = line->prev = line;
     line->offset = line->size = 0;
 #ifdef USE_COLOR_STYLE
@@ -2524,9 +2519,12 @@ PRIVATE HTLine * insert_blanks_in_line A
     if (line->size + added_chars > MAX_LINE - 2)
        return NULL;
     if (line == text->last_line)
-       mod_line = allocHTLine(MAX_LINE);
+       if (line == (HTLine*)tmp_long_line[0])
+          mod_line = (HTLine*)tmp_long_line[1];
+       else
+          mod_line = (HTLine*)tmp_long_line[0];
     else
-       mod_line = allocHTLine(line->size + added_chars);
+       POOLallocHTLine(mod_line, line->size + added_chars);
     if (!mod_line)
        return NULL;
     if (!prev_anchor)
@@ -2644,18 +2642,20 @@ 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;
-    /* can't wrap in middle of multibyte sequences, so allocate 2 extra */
-    HTLine * line = (HTLine *)LY_CALLOC(1, LINE_SIZE(MAX_LINE)+2);
+
+    HTLine * previous = text->last_line;
+    HTLine * line;

     /*
      *  Set new line.
      */
-    if (line == NULL)
-       outofmem(__FILE__, "split_line_1");
+    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));

     ctrl_chars_on_this_line = 0; /*reset since we are going to a new line*/


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

reply via email to

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