Update of /cvsroot/xine/xine-ui/src/xitk
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24704

Modified Files:
        viewlog.c 
Log Message:
Fixed segfault upon switching between sections caused by repeated freeing
of the same log[0] pointer due to missing NULL termination of empty log list
and counter limit of freeing loop off by one.
Fixed memleak on exit.
More efficient string operations (>90% time saving).


Index: viewlog.c
===================================================================
RCS file: /cvsroot/xine/xine-ui/src/xitk/viewlog.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- viewlog.c   19 Jun 2006 13:56:50 -0000      1.53
+++ viewlog.c   1 Dec 2006 23:28:10 -0000       1.54
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2000-2004 the xine project
+ * Copyright (C) 2000-2006 the xine project
  * 
  * This file is part of xine, a unix video player.
  * 
@@ -76,6 +76,7 @@
 
   if(viewlog) {
     window_info_t wi;
+    int           i;
     
     viewlog->running = 0;
     viewlog->visible = 0;
@@ -100,6 +101,10 @@
     
     free(viewlog->widget_list);
     
+    for(i = 0; i < viewlog->log_entries; i++)
+      free((char *)viewlog->log[i]);
+    free(viewlog->log);
+
     free(viewlog);
     viewlog = NULL;
 
@@ -187,21 +192,21 @@
   const char *p;
   
   /* Freeing entries */
-  for(i = 0; i <= viewlog->log_entries; i++) {
+  for(i = 0; i < viewlog->log_entries; i++)
     free((char *)viewlog->log[i]);
-  }
   
   /* Compute log entries */
-  viewlog->log_entries = viewlog->real_num_entries = k = 0;
+  viewlog->real_num_entries = j = k = 0;
   
   if(log) {
     
     /* Look for entries number */
     while(log[k] != NULL) k++;
 
-    for(i = 0, j = 0; i < k; i++) {
+    for(i = 0; i < k; i++) {
+      int buflen;
 
-      memset(&buf, 0, sizeof(buf));
+      buf[0] = '\0'; buflen = 0;
       
       p = &log[i][0];
       
@@ -220,16 +225,16 @@
            break;
            
          case '\n':
-           if(strlen(buf)) {
+           if(buflen > 0) {
              viewlog->log = (const char **) realloc(viewlog->log, sizeof(char 
**) * ((j + 1) + 1));
              viewlog->log[j++] = strdup(buf);
              viewlog->real_num_entries++;
            }
-           memset(&buf, 0, sizeof(buf));
+           buf[0] = '\0'; buflen = 0;
            break;
            
          default:
-           sprintf(buf+strlen(buf), "%c", *p);
+           buf[buflen++] = *p; buf[buflen] = '\0';
            break;
          }
          
@@ -237,7 +242,7 @@
        }
 
        /* Remaining chars */
-       if(strlen(buf)) {
+       if(buflen > 0) {
          viewlog->log = (const char **) realloc(viewlog->log, sizeof(char **) 
* ((j + 1) + 1));
          viewlog->log[j++] = strdup(buf);
        }
@@ -250,11 +255,11 @@
       }
     }
     
-    /* I like null terminated arrays ;-) */
-    viewlog->log[j]      = NULL;
-    viewlog->log_entries = j;
-    
   }
+
+  /* I like null terminated arrays ;-) */
+  viewlog->log[j]      = NULL;
+  viewlog->log_entries = j;
   
 #if DEBUG_VIEWLOG
   if((viewlog->log_entries == 0) || (log == NULL))


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Xine-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xine-cvslog

Reply via email to