]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-03-03 03:47:04 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 3 Mar 2004 03:47:04 +0000 (03:47 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Wed, 3 Mar 2004 03:47:04 +0000 (03:47 +0000)
big patch from Martin Hejl:
- use qprintf() where appropriate
- save CPU cycles on gettimeofday()
- add quit() functions to free allocated memory
- fixed lots of memory leaks

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@384 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

46 files changed:
Raster.c
Text.c
cfg.c
drv_HD44780.c
drv_generic_graphic.c
drv_generic_parport.c
drv_generic_serial.c
drv_generic_text.c
evaluator.c
evaluator.h
exec.c
hash.c
hash.h
imon.c
layout.c
lcd4linux.c
lock.c
mail.c
mail2.c
pid.c
plugin.c
plugin.h
plugin_cfg.c
plugin_cpuinfo.c
plugin_dvb.c
plugin_i2c_sensors.c
plugin_imon.c
plugin_loadavg.c
plugin_math.c
plugin_meminfo.c
plugin_netdev.c
plugin_ppp.c
plugin_proc_stat.c
plugin_sample.c
plugin_string.c
plugin_uname.c
plugin_xmms.c
seti.c
timer.c
timer.h
widget.c
widget.h
widget_bar.c
widget_icon.c
widget_text.c
wifi.c

index b0587a6183eca3ec67b14bcf42fde0f3b4b16084..0bf1b9152d0192730207c21a4d766a762113d9c2 100644 (file)
--- a/Raster.c
+++ b/Raster.c
@@ -1,4 +1,4 @@
-/* $Id: Raster.c,v 1.30 2004/01/30 20:57:55 reinelt Exp $
+/* $Id: Raster.c,v 1.31 2004/03/03 03:47:04 reinelt Exp $
  *
  * driver for raster formats
  *
  *
  *
  * $Log: Raster.c,v $
+ * Revision 1.31  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.30  2004/01/30 20:57:55  reinelt
  * HD44780 patch from Martin Hejl
  * dmalloc integrated
@@ -236,14 +243,14 @@ int PPM_flush (void)
   }
   
   snprintf (path, sizeof(path), output, seq++);
-  snprintf (tmp, sizeof(tmp), "%s.tmp", path);
+  qprintf(tmp, sizeof(tmp), "%s.tmp", path);
   
   if ((fd=open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0644))<0) {
     error ("Raster: open(%s) failed: %s", tmp, strerror(errno));
     return -1;
   }
   
-  snprintf (buffer, sizeof(buffer), "P6\n%d %d\n255\n", xsize, ysize);
+  qprintf(buffer, sizeof(buffer), "P6\n%d %d\n255\n", xsize, ysize);
   if (write (fd, buffer, strlen(buffer))<0) {
     error ("Raster: write(%s) failed: %s", tmp, strerror(errno));
     return -1;
@@ -328,7 +335,7 @@ int PNG_flush (void)
   }
   
   snprintf (path, sizeof(path), output, seq++);
-  snprintf (tmp, sizeof(tmp), "%s.tmp", path);
+  qprintf(tmp, sizeof(tmp), "%s.tmp", path);
   
   if ((fp=fopen(tmp, "w")) == NULL) {
     error("Png: fopen(%s) failed: %s\n", tmp, strerror(errno));
@@ -374,22 +381,31 @@ int Raster_init (LCD *Self)
   if (sscanf(s=cfg_get(NULL, "size", "20x4"), "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
     error ("Raster: bad size '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
 
   if (sscanf(s=cfg_get(NULL, "font", "5x8"), "%dx%d", &xres, &yres)!=2 || xres<5 || yres<7) {
     error ("Raster: bad font '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
 
   if (sscanf(s=cfg_get(NULL, "pixel", "4+1"), "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
     error ("Raster: bad pixel '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
 
   if (sscanf(s=cfg_get(NULL, "gap", "3x3"), "%dx%d", &cgap, &rgap)!=2 || cgap<-1 || rgap<-1) {
     error ("Raster: bad gap '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
+  
   if (rgap<0) rgap=pixel+pgap;
   if (cgap<0) cgap=pixel+pgap;
 
@@ -398,15 +414,23 @@ int Raster_init (LCD *Self)
   if (sscanf(s=cfg_get(NULL, "foreground", "#102000"), "#%x", &foreground)!=1) {
     error ("Raster: bad foreground color '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
+  
   if (sscanf(s=cfg_get(NULL, "halfground", "#70c000"), "#%x", &halfground)!=1) {
     error ("Raster: bad halfground color '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
+  
   if (sscanf(s=cfg_get(NULL, "background", "#80d000"), "#%x", &background)!=1) {
     error ("Raster: bad background color '%s'", s);
     return -1;
+    free(s);
   }
+  free(s);
 
   if (pix_init (rows, cols, xres, yres)!=0) {
     error ("Raster: pix_init(%d, %d, %d, %d) failed", rows, cols, xres, yres);
diff --git a/Text.c b/Text.c
index f318c7327bbdfaa0a5b3aa7010c8cf6d295d6d89..9499b0dfae748a5fca6bef6a3434d266d0e99211 100644 (file)
--- a/Text.c
+++ b/Text.c
@@ -1,4 +1,4 @@
-/* $Id: Text.c,v 1.14 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: Text.c,v 1.15 2004/03/03 03:47:04 reinelt Exp $
  *
  * pure ncurses based text driver
  *
  *
  *
  * $Log: Text.c,v $
+ * Revision 1.15  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.14  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -150,6 +157,7 @@ int Text_init (LCD *Self)
     error ("Text: bad size '%s'", s);
     return -1;
   }
+  free(s);
   Self->rows=rows;
   Self->cols=cols;
   Self->xres=1;
@@ -231,9 +239,10 @@ int Text_put (int row, int col, char *text)
 int Text_bar (int type, int row, int col, int max, int len1, int len2)
 {
   int len, i;
-  if (cfg_get(NULL, "TextBar", NULL)) 
+  char* s;
+  if (s=cfg_get(NULL, "TextBar", NULL)) {
     mvwprintw(w, row+1 , col+1, "%d %d %d", max, len1, len2);
-  else {
+  else {
     len = min(len1, len2);
     len = min(len, Lcd.cols-col-1);
     if (len) {
@@ -251,7 +260,7 @@ int Text_bar (int type, int row, int col, int max, int len1, int len2)
     for (i=0; i<len2;i++)
       waddch(w,ACS_S9);
   }
-  
+  free(s);  
   return 0;
 }
 
diff --git a/cfg.c b/cfg.c
index 5fb008792ce5a11fc3fe2180d232f35904b0ea88..dd6d2c3ad8ffa1f2e3d9882a818eb96693618c89 100644 (file)
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.35 2004/03/01 04:29:51 reinelt Exp $^
+/* $Id: cfg.c,v 1.36 2004/03/03 03:47:04 reinelt Exp $^
  *
  * config file stuff
  *
  *
  *
  * $Log: cfg.c,v $
+ * Revision 1.36  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.35  2004/03/01 04:29:51  reinelt
  * cfg_number() returns -1 on error, 0 if value not found (but default val used),
  *  and 1 if value was used from the configuration.
@@ -463,6 +470,7 @@ char *l4l_cfg_get_raw (char *section, char *key, char *defval)
 char *l4l_cfg_get (char *section, char *key, char *defval)
 {
   char *expression;
+  char *retval;
   RESULT result = {0, 0.0, NULL};
   
   expression=cfg_lookup(section, key);
@@ -470,10 +478,14 @@ char *l4l_cfg_get (char *section, char *key, char *defval)
   if (expression!=NULL) {
     if (*expression=='\0') return "";
     if (Eval(expression, &result)==0) {
-      return R2S(&result);
+      retval=strdup(R2S(&result));
+      DelResult(&result);        
+         return(retval);
     }
+    DelResult(&result);
   }
-  return strdup(defval);
+  if (defval) return strdup(defval);
+  return NULL;
 }
 
 
@@ -493,6 +505,7 @@ int l4l_cfg_number (char *section, char *key, int defval, int min, int max, int
   }
   
   if (Eval(expression, &result)!=0) {
+    DelResult(&result);
     return -1;
   }
   *value=R2N(&result);
@@ -724,8 +737,7 @@ char *l4l_cfg_source (void)
 int l4l_cfg_exit (void)
 {
   int i;
-  
-  for (i=0; i<nConfig; i++) {
+  for (i=0; i<nConfig; i++) {    
     if (Config[i].key) free (Config[i].key);
     if (Config[i].val) free (Config[i].val);
   }
index 62b5e3bc912a2d421810c59044a225c47ff9a238..f30f0c7969be4ba04e75f0d2290a3a1da8e6ab18 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_HD44780.c,v 1.14 2004/03/01 04:29:51 reinelt Exp $
+/* $Id: drv_HD44780.c,v 1.15 2004/03/03 03:47:04 reinelt Exp $
  *
  * new style driver for HD44780-based displays
  *
  *
  *
  * $Log: drv_HD44780.c,v $
+ * Revision 1.15  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.14  2004/03/01 04:29:51  reinelt
  * cfg_number() returns -1 on error, 0 if value not found (but default val used),
  *  and 1 if value was used from the configuration.
@@ -519,7 +526,7 @@ static void drv_HD_setGPO (int bits)
 
 static int drv_HD_start (char *section)
 {
-  char *model, *s;
+  char *model, *strsize;
   int rows=-1, cols=-1, gpos=-1;
   
   model=cfg_get(section, "Model", "generic");
@@ -539,17 +546,20 @@ static int drv_HD_start (char *section)
     error ("%s: empty '%s.Model' entry from %s", Name, section, cfg_source());
     return -1;
   }
+  free(model);
 
-  s=cfg_get(section, "Size", NULL);
-  if (s==NULL || *s=='\0') {
+  strsize=cfg_get(section, "Size", NULL);
+  if (strsize==NULL || *strsize=='\0') {
     error ("%s: no '%s.Size' entry from %s", Name, section, cfg_source());
+       free(strsize);
     return -1;
   }
-  if (sscanf(s,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) {
-    error ("%s: bad size '%s'", Name, s);
+  if (sscanf(strsize,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) {
+    error ("%s: bad size '%s'", Name, strsize);
+       free(strsize);
     return -1;
   }
-  
+    
   if (cfg_number(section, "GPOs", 0, 0, 8, &gpos)<0) return -1;
   info ("%s: controlling %d GPO's", Name, gpos);
 
@@ -568,7 +578,7 @@ static int drv_HD_start (char *section)
   
   if (cfg_number(section, "Bits", 8, 4, 8, &Bits)<0) return -1;
   if (Bits!=4 && Bits!=8) {
-    error ("%s: bad %s.Bits '%s' from %s, should be '4' or '8'", Name, section, s, cfg_source());
+    error ("%s: bad %s.Bits '%s' from %s, should be '4' or '8'", Name, section, strsize, cfg_source());
     return -1;
   }    
   info ("%s: using %d bit mode", Name, Bits);
@@ -638,6 +648,7 @@ static int drv_HD_start (char *section)
   }
   
   info("%s: %susing busy-flag checking", Name, UseBusy?"":"not ");
+  free(strsize);
 
   drv_HD_command (allControllers, 0x01, T_CLEAR); // clear *both* displays
   drv_HD_command (allControllers, 0x03, T_CLEAR); // return home
index d7968f75f044792a88b99c56e7090dcd45ced4a4..c51e22e344dd7c989bd5d8bb4d8d4a8efcdfff2b 100644 (file)
  *
  *
  * $Log: drv_generic_graphic.c,v $
+ * Revision 1.6  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.5  2004/02/29 14:30:59  reinelt
  * icon visibility fix for generic graphics from Xavier
  *
@@ -310,5 +317,6 @@ int drv_generic_graphic_quit (void)
     drv_generic_graphic_FB=NULL;
   }
   
+  widget_unregister();  
   return (0);
 }
index 68d537f80c652f6ad88cdb275b7cc080aa9cf0ef..c9aac3db56ee2c0efa31a665de134b673b304260 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_generic_parport.c,v 1.2 2004/01/20 15:32:49 reinelt Exp $
+/* $Id: drv_generic_parport.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic driver helper for serial and parport access
  *
  *
  *
  * $Log: drv_generic_parport.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/01/20 15:32:49  reinelt
  * first version of Next Generation HD44780 (untested! but it compiles...)
  * some cleanup in the other drivers
@@ -85,6 +92,7 @@
 #include "cfg.h"
 #include "udelay.h"
 #include "drv_generic_parport.h"
+#include "qprintf.h"
 
 
 static char *Driver="";
@@ -120,6 +128,7 @@ int drv_generic_parport_open (char *section, char *driver)
     Port=0;
     PPdev=s;
 #else
+    free(s);
     error ("%s: bad %s.Port '%s' from %s", Driver, Section, s, cfg_source());
     return -1;
 #endif
@@ -183,6 +192,7 @@ int drv_generic_parport_close (void)
       error ("%s: close(%s) failed: %s", Driver, PPdev, strerror(errno));
       return -1;
     }
+    free(PPdev);
   } else 
 #endif    
     {
@@ -199,6 +209,7 @@ int drv_generic_parport_close (void)
        }
       }
     }
+
   return 0;
 }
 
@@ -209,7 +220,7 @@ unsigned char drv_generic_parport_wire_ctrl (char *name, unsigned char *deflt)
   char wire[256];
   char *s;
   
-  snprintf (wire, sizeof(wire), "Wire.%s", name);
+  qprintf(wire, sizeof(wire), "Wire.%s", name);
   s=cfg_get (Section, wire, deflt);
   if (strcasecmp(s,"STROBE")==0) {
     w=PARPORT_CONTROL_STROBE;
@@ -226,6 +237,7 @@ unsigned char drv_generic_parport_wire_ctrl (char *name, unsigned char *deflt)
     error ("%s: should be STROBE, AUTOFD, INIT, SELECT or GND", Driver);
     return 0xff;
   }
+  free(s);
 
   if (w&PARPORT_CONTROL_STROBE) {
     info ("%s: wiring: [DISPLAY:%s]<==>[PARPORT:STROBE]", Driver, name);
@@ -253,7 +265,7 @@ unsigned char drv_generic_parport_wire_data (char *name, unsigned char *deflt)
   char wire[256];
   char *s;
   
-  snprintf (wire, sizeof(wire), "Wire.%s", name);
+  qprintf(wire, sizeof(wire), "Wire.%s", name);
   s=cfg_get (Section, wire, deflt);
   if(strlen(s)==3 && strncasecmp(s,"DB",2)==0 && s[2]>='0' && s[2]<='7') {
     w=s[2]-'0';
@@ -264,7 +276,7 @@ unsigned char drv_generic_parport_wire_data (char *name, unsigned char *deflt)
     error ("%s: should be DB0..7 or GND", Driver);
     return 0xff;
   }
-  
+  free(s);
   if (w==0) {
     info ("%s: wiring: [DISPLAY:%s]<==>[PARPORT:GND]", Driver, name);
   } else {
index 46c524d6fbc7d6c170553c7463278a554014761e..a4cb31289725f69ed4f4aaa2725d5d032754587d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_generic_serial.c,v 1.6 2004/02/14 11:56:17 reinelt Exp $
+/* $Id: drv_generic_serial.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic driver helper for serial and usbserial displays
  *
  *
  *
  * $Log: drv_generic_serial.c,v $
+ * Revision 1.7  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.6  2004/02/14 11:56:17  reinelt
  * M50530 driver ported
  * changed lots of 'char' to 'unsigned char'
 #include "debug.h"
 #include "cfg.h"
 #include "drv_generic_serial.h"
+#include "qprintf.h"
 
 
 static char   *Driver;
@@ -127,8 +135,8 @@ pid_t drv_generic_serial_lock_port (char *Port)
     *p='_';
   }
   
-  snprintf(lockfile, sizeof(lockfile), LOCK, port);
-  snprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
+  qprintf(lockfile, sizeof(lockfile), LOCK, port);
+  qprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
 
   free (port);
   
@@ -222,7 +230,7 @@ static pid_t drv_generic_serial_unlock_port (char *Port)
     *p='_';
   }
   
-  snprintf(lockfile, sizeof(lockfile), LOCK, port);
+  qprintf(lockfile, sizeof(lockfile), LOCK, port);
   unlink (lockfile);
   free (port);
 
@@ -353,6 +361,7 @@ int drv_generic_serial_close (void)
   info ("%s: closing port %s", Driver, Port);
   close (Device);
   drv_generic_serial_unlock_port(Port);
+  free(Port);
   return 0;
 }
 
index 60b7875b846467d9c605332146ecd74405c3f3c9..3fd5666322628411b7e65acbd8ad20bb75709b11 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: drv_generic_text.c,v 1.11 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: drv_generic_text.c,v 1.12 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic driver helper for text-based displays
  *
  *
  *
  * $Log: drv_generic_text.c,v $
+ * Revision 1.12  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.11  2004/02/15 21:43:43  reinelt
  * T6963 driver nearly finished
  * framework for graphic displays done
@@ -740,6 +747,7 @@ int drv_generic_text_quit (void) {
     free (BarFB);
     BarFB=NULL;
   }
-  
+  widget_unregister();
+
   return (0);
 }
index 17fee4ce705d6bcab98487bc4b3da1c8f84389e5..7700c5ab472de38dd125fa4fbed43d456482eb0d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.c,v 1.13 2004/02/26 21:42:45 reinelt Exp $
+/* $Id: evaluator.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
  *
  * expression evaluation
  *
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.c,v $
+ * Revision 1.14  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.13  2004/02/26 21:42:45  reinelt
  * memory leak fixes from Martin
  *
@@ -396,7 +403,7 @@ int SetVariable (char *name, RESULT *value)
   V=bsearch(name, Variable, nVariable, sizeof(VARIABLE), v_lookup);
   if (V!=NULL) {
     FreeResult (V->value);
-    V->value=DupResult(value);
+    V->value=(value);
     return 1;
   }
   
@@ -413,6 +420,17 @@ int SetVariable (char *name, RESULT *value)
   return 0;
 }
 
+void DeleteVariables(void) {
+       int i;
+       
+       for (i=0;i<nVariable;i++) {
+               free(Variable[i].name);
+               FreeResult(Variable[i].value);
+       }
+       free(Variable);
+       Variable=NULL;
+       nVariable=0;
+}
 
 int AddNumericVariable (char *name, double value)
 {
@@ -486,6 +504,17 @@ int AddFunction (char *name, int args, void (*func)())
   return 0;
 }
 
+void DeleteFunctions(void) {
+       int i;
+       
+       for (i=0;i<nFunction;i++) {
+               free(Function[i].name);
+       }
+       free(Function);
+       Function=NULL;
+       nFunction=0;
+}
+
 
 
 // Prototypes
@@ -640,13 +669,14 @@ static void Level04 (RESULT *result)
     value = (R2N(result)!=0.0) || (R2N(&operand)!=0.0);
     SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&operand);
 }
 
 
 // logical 'and'
 static void Level05 (RESULT *result)
 {
-  RESULT operand;
+  RESULT operand = {0, 0.0, NULL};
   double value;
   
   Level06(result);
@@ -657,6 +687,7 @@ static void Level05 (RESULT *result)
     value = (R2N(result)!=0.0) && (R2N(&operand)!=0.0);
     SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&operand);
 }
 
 
@@ -676,8 +707,9 @@ static void Level06 (RESULT *result)
       value = (R2N(result) == R2N(&operand));
     else
       value = (R2N(result) != R2N(&operand));
-    SetResult(&result, R_NUMBER, &value); 
+      SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&operand);
 }
 
 
@@ -697,16 +729,17 @@ static void Level07 (RESULT *result)
     Level08 (&operand);
     if (operator[0]=='<')
       if (operator[1]=='=')
-       value = (R2N(result) <= R2N(&operand));
+        value = (R2N(result) <= R2N(&operand));
       else
-       value = (R2N(result) <  R2N(&operand));
+        value = (R2N(result) <  R2N(&operand));
     else
       if (operator[1]=='=')
-       value = (R2N(result) >= R2N(&operand));
+        value = (R2N(result) >= R2N(&operand));
       else
-       value = (R2N(result) >  R2N(&operand));
+        value = (R2N(result) >  R2N(&operand));
     SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&operand);
 }
 
 
@@ -738,6 +771,7 @@ static void Level08 (RESULT *result)
       free (s3);
     }
   }
+  DelResult(&operand);
 }
 
 
@@ -764,6 +798,7 @@ static void Level09 (RESULT *result)
     }
     SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&operand);
 }
 
 
@@ -781,6 +816,7 @@ static void Level10 (RESULT *result)
     value = pow(R2N(result), R2N(&exponent));
     SetResult(&result, R_NUMBER, &value); 
   }
+  DelResult(&exponent);
 }
 
 
index 9ace1028ea01ac1cb2eb89a409c1605059a3fbf9..35e298151aac665785ed1194a7be21b4d8ac5dfa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: evaluator.h,v 1.3 2004/01/12 03:51:01 reinelt Exp $
+/* $Id: evaluator.h,v 1.4 2004/03/03 03:47:04 reinelt Exp $
  *
  * expression evaluation
  *
  * FIXME: GPL or not GPL????
  *
  * $Log: evaluator.h,v $
+ * Revision 1.4  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.3  2004/01/12 03:51:01  reinelt
  * evaluating the 'Variables' section in the config file
  *
@@ -92,6 +99,8 @@ int SetVariable        (char *name, RESULT *value);
 int AddNumericVariable (char *name, double value);
 int AddStringVariable  (char *name, char *value);
 int AddFunction        (char *name, int args, void (*func)());
+void DeleteVariables   (void);
+void DeleteFunctions   (void);
 
 RESULT* SetResult (RESULT **result, int type, void *value);
 
diff --git a/exec.c b/exec.c
index b64653f3d03fdc4b627e3dd8354a25f0c31a5117..194641d2f2c6c471c902e4cb157369a830452b1a 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1,4 +1,4 @@
-/* $Id: exec.c,v 1.12 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: exec.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
  *
  * exec ('x*') functions
  *
  *
  *
  * $Log: exec.c,v $
+ * Revision 1.13  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.12  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -93,7 +100,7 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
   static time_t now[EXECS+1];
   static int errs[EXECS+1];
   static int ticks[EXECS+1];
-  char *command, *p;
+  char *command, *strticks;
   char xn[20];
   char env[EXEC_TXT_LEN];
   FILE *pipe;
@@ -113,12 +120,16 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
   if (now[index] > 0) {
     /* delay in Ticks ? */
     sprintf(xn, "Tick_x%d", index);
-    p = cfg_get(NULL, xn, NULL);
+    strticks = cfg_get(NULL, xn, NULL);
     if (p && *p) {
-      if (ticks[index]++ % atoi(p) != 0)
+      if (ticks[index]++ % atoi(strticks) != 0) {
+           free(strticks);
         return 0;
+      }
+         free(strticks);
     }
     else {
+         free(strticks);       
       sprintf(xn, "Delay_x%d", index);
       /* delay in Delay_x* sec ? */
       if (time(NULL) <= now[index] + atoi(cfg_get(NULL, xn, "1"))) {
@@ -135,6 +146,7 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
   if (!command || !*command) {
     error("Empty command for 'x%d'", index);
     errs[index]++;
+       if (command) free(command);
     return -1;
   }
   for (i = 1; i < index; i++) {
@@ -146,6 +158,7 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
   if (pipe == NULL) {
     error("Couldn't run pipe '%s':\n%s", command, strerror(errno));
     errs[index]++;
+       free(command);
     return -1;
   }
   len = fread(buff, 1, EXEC_TXT_LEN-1,  pipe);
@@ -154,6 +167,7 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
     error("Couldn't fread from pipe '%s', len=%d", command, len);
     errs[index]++;
     *buff = '\0';
+       free(command);
     return -1;
   }
   pclose(pipe);
@@ -176,6 +190,7 @@ int Exec(int index, char buff[EXEC_TXT_LEN], double *val)
     if (max != min)
       *val = (*val - min)/(max - min);
   }
+  free(command);
   return 0;
 }
 
diff --git a/hash.c b/hash.c
index 0167466b6e2efc8217c3a993b4a3fa0452377512..f263e8a0cb75dac8e2ddcfdddb0a44bfd76ffe39 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -1,4 +1,4 @@
-/* $Id: hash.c,v 1.13 2004/02/27 06:07:55 reinelt Exp $
+/* $Id: hash.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
  *
  * hashes (associative arrays)
  *
  *
  *
  * $Log: hash.c,v $
+ * Revision 1.14  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.13  2004/02/27 06:07:55  reinelt
  * hash improvements from Martin
  *
 
 #define DELTA_SLOTS 64
 
+static timeval __my_time_of_day;
+
+int gettimeofday_ex(timeval *tv, struct timezone *tz) {
+  if (tv==NULL) return -1;
+
+  if (__my_time_of_day.tv_usec == 0 && __my_time_of_day.tv_sec==0) {
+    gettimeofday_update();
+  }
+
+  tv->tv_sec = __my_time_of_day.tv_sec;
+  tv->tv_usec= __my_time_of_day.tv_usec;
+  return 0;
+}
+
+void gettimeofday_update(){
+  gettimeofday(&__my_time_of_day, NULL);
+}
+
 
 // bsearch compare function for hash entries
 static int hash_lookup_f (const void *a, const void *b)
@@ -191,7 +216,7 @@ static HASH_ITEM* hash_set_string (HASH *Hash, char *key, char *val)
 
  hash_got_string:
   // set timestamps
-  gettimeofday(&Hash->time, NULL);
+  gettimeofday_ex(&Hash->time, NULL);
   Item->time=Hash->time;
 
   return Item;
@@ -231,7 +256,7 @@ void hash_set_delta (HASH *Hash, char *key, char *val)
   if (--Item->root < 0) Item->root = DELTA_SLOTS-1;
 
   // set first entry
-  gettimeofday(&(Item->Slot[Item->root].time), NULL);
+  gettimeofday_ex(&(Item->Slot[Item->root].time), NULL);
   Item->Slot[Item->root].val=number;
 
 }
@@ -255,6 +280,8 @@ int hash_age (HASH *Hash, char *key, char **value)
   timeval now, *stamp;
   int age;
   
+  gettimeofday_update();
+  
   if (key!=NULL) {
     Item=hash_lookup(Hash, key, 1);
     if (value) *value=Item?Item->val:NULL;
@@ -266,7 +293,7 @@ int hash_age (HASH *Hash, char *key, char **value)
     stamp=&Hash->time;
   }
   
-  gettimeofday(&now, NULL);
+  gettimeofday_ex(&now, NULL);
   
   age = (now.tv_sec - stamp->tv_sec)*1000 + (now.tv_usec - stamp->tv_usec)/1000;
 
diff --git a/hash.h b/hash.h
index cefdc5069ccd0bcd22c0012a51db490bcde4554d..1130661ed081a1b91b4a488dbe7014854f2cf66f 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -1,4 +1,4 @@
-/* $Id: hash.h,v 1.8 2004/02/27 06:07:55 reinelt Exp $
+/* $Id: hash.h,v 1.9 2004/03/03 03:47:04 reinelt Exp $
  *
  * hashes (associative arrays)
  *
  *
  *
  * $Log: hash.h,v $
+ * Revision 1.9  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.8  2004/02/27 06:07:55  reinelt
  * hash improvements from Martin
  *
@@ -95,4 +102,8 @@ char  *hash_get       (HASH *Hash, char *key);
 double hash_get_delta (HASH *Hash, char *key, int delay);
 double hash_get_regex (HASH *Hash, char *key, int delay);
 void   hash_destroy   (HASH *Hash);
+
+int gettimeofday_ex(struct timeval *tv, struct timezone *tz); 
+void gettimeofday_update();
+
 #endif
diff --git a/imon.c b/imon.c
index bd329b9367a0c8e246efda5e5297b187f535b757..40a52b851a32c2a824eb159fe6e3ff8471126b14 100755 (executable)
--- a/imon.c
+++ b/imon.c
@@ -1,4 +1,4 @@
-/* $Id: imon.c,v 1.4 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: imon.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
  *
  * imond/telmond data processing
  *
  *
  *
  * $Log: imon.c,v $
+ * Revision 1.5  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.4  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -225,7 +232,7 @@ get_value (char * cmd)
 
 
 int init(){
- char *s, *host;
+ char *pwd, *host, *answer;
  int port;
  int connect;
 
@@ -241,20 +248,23 @@ int init(){
  
  connect=service_connect(host,port);
 
s=cfg_get (NULL, "Imon_Pass", NULL);
- if ((s!=NULL) && (*s!='\0')) { // Passwort senden
pwd=cfg_get (NULL, "Imon_Pass", NULL);
+ if ((pwd!=NULL) && (*pwd!='\0')) { // Passwort senden
    char buf[40];
-   sprintf(buf,"pass %s",s);
+   sprintf(buf,"pass %s",pwd);
    send_command(connect,buf);
-   s=get_answer(connect); 
+   answer=get_answer(connect); 
  }
+ free(host);
+ free(pwd):
  
  return connect;       
 }
  
 int ImonCh(int index, struct imonchannel *ch, int token_usage[]) {
  static int err[CHANNELS+1];
- char *s;
+ char *cfg_string;
  char buf[40];
  int result=0;
  
@@ -263,13 +273,14 @@ int ImonCh(int index, struct imonchannel *ch, int token_usage[]) {
         
  if ((*ch).max_in == 0){ // not initializied
   sprintf(buf, "Imon_%d_Dev", index);
-  s=cfg_get(NULL, buf, NULL);
-  if (s==NULL) {
+  cfg_string=cfg_get(NULL, buf, NULL);
+  if (cfg_string==NULL) {
    error ("Imon: no 'Imon_%i_Dev' entry in %s", index, cfg_source());
    err[index]=1;
    return -1;
   } 
-  strcpy((*ch).dev,s);
+  strcpy((*ch).dev,cfg_string);
+  free(cfg_string);
   
   sprintf(buf, "Imon_%d_MaxIn", index);
   cfg_number(NULL, buf,768,1,65536,&(*ch).max_in);
@@ -384,9 +395,10 @@ char* ImonVer(){
 void phonebook(char *number){
   FILE *  fp;
   char line[256];
+  char* filename;
   
-  fp = fopen (cfg_get (NULL, "Telmon_Phonebook","/etc/phonebook"), "r");
-  
+  fp = fopen (filename=cfg_get (NULL, "Telmon_Phonebook","/etc/phonebook"), "r");
+  free(filename);
   if (! fp) return;
   
   while (fgets (line, 128, fp)){
@@ -423,6 +435,7 @@ int Telmon(struct telmon *t){
    return -1;
   } 
   strcpy(host,s);
+  free(s);
   
   if (cfg_number(NULL, "Telmon_Port",5000,1,65536,&port)<0){
    telmond_fd=-1;
index 451d80aa525f57f9465331be70c602955cae7300..312e1ef3787484e20ff176389207cddafb976408 100644 (file)
--- a/layout.c
+++ b/layout.c
@@ -1,4 +1,4 @@
-/* $Id: layout.c,v 1.9 2004/02/01 19:37:40 reinelt Exp $
+/* $Id: layout.c,v 1.10 2004/03/03 03:47:04 reinelt Exp $
  *
  * new layouter framework
  *
  *
  *
  * $Log: layout.c,v $
+ * Revision 1.10  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.9  2004/02/01 19:37:40  reinelt
  * got rid of every strtok() incarnation.
  *
@@ -125,14 +132,15 @@ int layout_init (char *layout)
     if (i==2 && l[n]=='\0') {
       widget=cfg_get(section, l, NULL);
       if (widget!=NULL && *widget!='\0') {
-       layout_addItem (widget, row, col);
+        layout_addItem (widget, row, col);
       }
+         free(widget);
     }
     // next field
     l=p?p+1:NULL;
   }
   free (list);
-  
+  free(section);
   return 0;
 }
 
index 764f67e5244fa1fc44b552bc52411d1d018eadba..5d73d34b903ca581e1d2606afb56ad6c7dfd80e0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.64 2004/02/27 07:06:25 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.65 2004/03/03 03:47:04 reinelt Exp $
  *
  * LCD4Linux
  *
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.65  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.64  2004/02/27 07:06:25  reinelt
  * new function 'qprintf()' (simple but quick snprintf() replacement)
  *
@@ -478,7 +485,8 @@ int main (int argc, char *argv[])
     exit (1);
   }
   
-  snprintf (section, sizeof(section), "Display:%s", display);
+  qprintf(section, sizeof(section), "Display:%s", display);
+  free(display);
   driver=cfg_get(section, "Driver", NULL);
   if (driver==NULL || *driver=='\0') {
     error ("missing '%s.Driver' entry in %s!", section, cfg_source());
@@ -542,6 +550,7 @@ int main (int argc, char *argv[])
     pid_exit(PIDFILE);
     exit (1);
   }
+  free(driver);
   
   // check for new-style layout
   layout=cfg_get(NULL, "Layout", NULL);
@@ -551,6 +560,7 @@ int main (int argc, char *argv[])
   }
   
   layout_init(layout);
+  free(layout);
 
   // maybe go into interactive mode
   if (interactive) {
@@ -613,10 +623,10 @@ int main (int argc, char *argv[])
   if (!quiet) hello();
 #endif
   drv_quit();
-
   pid_exit(PIDFILE);
   cfg_exit();
-    
+  plugin_exit();    
+  timer_exit();
   if (got_signal==SIGHUP) {
     long fd;
     debug ("restarting...");
@@ -630,6 +640,11 @@ int main (int argc, char *argv[])
     error ("execv() failed: %s", strerror(errno));
     exit(1);
   }
+  
+  for(c=0;my_argv[c]!=NULL;c++) {
+    free(my_argv[c]);
+  }
+  free(my_argv);
   exit (0);
 }
   
diff --git a/lock.c b/lock.c
index f7f42dec5bb05ab1ac16f019fd7233e360cd82ef..b03a555d6aec5cd2153d95c7bf7eccf3d7635bcc 100644 (file)
--- a/lock.c
+++ b/lock.c
@@ -1,4 +1,4 @@
-/* $Id: lock.c,v 1.6 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: lock.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
  *
  * UUCP style locking
  *
  *
  *
  * $Log: lock.c,v $
+ * Revision 1.7  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.6  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -80,6 +87,7 @@
 
 #include "debug.h"
 #include "lock.h"
+#include "qprintf.h"
 
 
 pid_t lock_port (char *Port)
@@ -100,8 +108,8 @@ pid_t lock_port (char *Port)
     *p='_';
   }
   
-  snprintf(lockfile, sizeof(lockfile), LOCK, port);
-  snprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
+  qprintf(lockfile, sizeof(lockfile), LOCK, port);
+  qprintf(tempfile, sizeof(tempfile), LOCK, "TMP.XXXXXX");
 
   free (port);
   
@@ -195,7 +203,7 @@ pid_t unlock_port (char *Port)
     *p='_';
   }
   
-  snprintf(lockfile, sizeof(lockfile), LOCK, port);
+  qprintf(lockfile, sizeof(lockfile), LOCK, port);
   unlink (lockfile);
   free (port);
 
diff --git a/mail.c b/mail.c
index 40a10fece54d6b543b11b6fe41350e3b88b83232..68f29b6ebf53f5c857a682c68e6dff6af287cac4 100644 (file)
--- a/mail.c
+++ b/mail.c
@@ -1,4 +1,4 @@
-/* $Id: mail.c,v 1.15 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: mail.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
  *
  * email specific functions
  *
  *
  *
  * $Log: mail.c,v $
+ * Revision 1.16  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.15  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -121,6 +128,8 @@ int Mail (int index, int *num, int *unseen)
   int last_line_blank1;                   // Was the last line blank?
   struct stat fst;
   int rc;
+  char *s:
+  int i;
 
   char *txt;
   char txt1[100];
@@ -137,14 +146,17 @@ int Mail (int index, int *num, int *unseen)
   }
   if (now[index] > 0) {        /* not first time, delay  */
     sprintf(txt1, "Delay_e%d", index); 
-    if (time(NULL)<=now[index]+atoi(cfg_get(NULL, txt1, "5"))) 
+    s= cfg_get(NULL, txt1, "5");
+    i=now[index]+atoi(s);
+    free(s);
+    if (time(NULL)<=i)
       return 0;   // no more then 5/Delay_eX seconds after last check?
   }
   time(&now[index]);                      // for Mailbox #index
   /*
     Build the filename from the config
   */
-  snprintf(buffer, sizeof(buffer), "Mailbox%d", index);
+  qprintf(buffer, sizeof(buffer), "Mailbox%d", index);
   fnp1=cfg_get(NULL, buffer, NULL);
   if (fnp1==NULL || *fnp1=='\0') {
     cfgmbx[index]=FALSE;                  // There is now entry for Mailbox #index
@@ -163,10 +175,13 @@ int Mail (int index, int *num, int *unseen)
         is it pop3, imap4 or nntp? 
       */
       rc = Mail_pop_imap_news(fnp1, num, unseen);
-      if (rc == 0)
-       return 0;
+      if (rc == 0) {
+            free(fnp1);
+                       return 0;
+               }
       else
        cfgmbx[index] = FALSE; /* don't try again */
+       
       error ("Error getting stat of Mailbox%d", index);
       return (-1);
     }
@@ -174,7 +189,6 @@ int Mail (int index, int *num, int *unseen)
       mbxlt[index]=fst.st_mtime;
 
       fstr=fopen(fnp1,"r");
-
       if (fstr != NULL) {
         txt=&txt1[0];
         last_line_blank1=TRUE;
@@ -202,6 +216,7 @@ int Mail (int index, int *num, int *unseen)
       }
     }
   }
+  free(fnp1);
   /* FIXME look at the Status of Mails */
   *unseen = v1 - mbxnum[index];
   if (*unseen < 0)
diff --git a/mail2.c b/mail2.c
index 4de52add488f249ff6807d532c7cbf33fed8ff2b..63cc604744e77d06a44a3dbffeaa4dfb8efc988b 100644 (file)
--- a/mail2.c
+++ b/mail2.c
@@ -1,4 +1,4 @@
-/* $Id: mail2.c,v 1.12 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: mail2.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
  *
  * mail: pop3, imap, news functions
  *
  *
  *
  * $Log: mail2.c,v $
+ * Revision 1.13  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.12  2004/01/30 20:57:56  reinelt
  * HD44780 patch from Martin Hejl
  * dmalloc integrated
@@ -221,16 +228,18 @@ static int check_nntp(char *user, char *pass, char *machine,
   int err;
   int totg, unsg;
   int first;
+  char *s;
   
   *total = 0;
   *unseen = 0;
   
-  strcpy(buf, cfg_get(NULL, "Newsrc", ".newsrc"));
+  strcpy(buf, (s=cfg_get(NULL, "Newsrc", ".newsrc")));
   if (*buf == 0 || ((fp = fopen(buf, "r")) == NULL)) {
     error("Couldn't open .newsrc-file '%s'", buf);
+       free(s);
     return -1;
   }
-
+  free(s);
   fd = open_socket(machine, port);
   if (fd < 0)
     {
diff --git a/pid.c b/pid.c
index bdf77370aa761fea21174e4394ef6b7529ef4488..743470a9af9ca598c9ffc633323b75f816bf98cf 100644 (file)
--- a/pid.c
+++ b/pid.c
@@ -1,4 +1,4 @@
-/* $Id: pid.c,v 1.3 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: pid.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
  *
  * PID file handling
  *
  *
  *
  * $Log: pid.c,v $
+ * Revision 1.4  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.3  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -62,7 +69,7 @@
 
 #include "debug.h"
 #include "pid.h"
-
+#include "qprintf.h"
 
 int pid_init (const char *pidfile)
 {
@@ -70,7 +77,7 @@ int pid_init (const char *pidfile)
   char buffer[16];
   int fd, len, pid;
   
-  snprintf(tmpfile, sizeof(tmpfile), "%s.%s", pidfile, "XXXXXX");
+  qprintf(tmpfile, sizeof(tmpfile), "%s.%s", pidfile, "XXXXXX");
 
   if ((fd=mkstemp(tmpfile))==-1) {
     error ("mkstemp(%s) failed: %s", tmpfile, strerror(errno));
@@ -84,7 +91,7 @@ int pid_init (const char *pidfile)
     return -1;
   }
   
-  snprintf (buffer, sizeof(buffer), "%d\n", (int)getpid());
+  qprintf(buffer, sizeof(buffer), "%d\n", (int)getpid());
   if (write(fd, buffer, strlen(buffer))!=strlen(buffer)) {
     error ("write(%s) failed: %s", tmpfile, strerror(errno));
     close(fd);
index 7e1c36b7c54088dc7fac3f9ece9d1d978747a7d8..0dc4e54e0d4786a9778ba6344a13e50826cd80e1 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -1,4 +1,4 @@
-/* $Id: plugin.c,v 1.19 2004/02/18 14:45:42 nicowallmeier Exp $
+/* $Id: plugin.c,v 1.20 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin handler for the Evaluator
  *
  *
  *
  * $Log: plugin.c,v $
+ * Revision 1.20  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.19  2004/02/18 14:45:42  nicowallmeier
  * Imon/Telmon plugin ported
  *
@@ -151,6 +158,21 @@ int plugin_init_xmms (void);
 int plugin_init_imon(void);
 
 
+void plugin_exit_math (void);
+void plugin_exit_string (void);
+void plugin_exit_cfg (void);
+void plugin_exit_uname (void);
+void plugin_exit_loadavg (void);
+void plugin_exit_proc_stat (void);
+void plugin_exit_cpuinfo (void);
+void plugin_exit_meminfo (void);
+void plugin_exit_netdev (void);
+void plugin_exit_ppp (void);
+void plugin_exit_dvb (void);
+void plugin_exit_i2c_sensors (void);
+void plugin_exit_xmms (void);
+void plugin_exit_imon(void);
+
 int plugin_init (void)
 {
   plugin_init_math();
@@ -171,4 +193,22 @@ int plugin_init (void)
   return 0;
 }
 
-
+void plugin_exit(void) {
+  plugin_exit_math();
+  plugin_exit_string();
+  plugin_exit_cfg();
+  plugin_exit_uname();
+  plugin_exit_loadavg();
+  plugin_exit_proc_stat();
+  plugin_exit_cpuinfo();
+  plugin_exit_meminfo();
+  plugin_exit_netdev();
+  plugin_exit_ppp();
+  plugin_exit_dvb();
+  plugin_exit_i2c_sensors();
+  plugin_exit_xmms();
+  plugin_exit_imon();  
+  
+  DeleteFunctions();
+  DeleteVariables();
+}
index d860c31559c3d50966bbb32a41e49fd2d76a1775..61a9aa0ed02566dd7f91030de29ab27f29cd88de 100644 (file)
--- a/plugin.h
+++ b/plugin.h
@@ -1,4 +1,4 @@
-/* $Id: plugin.h,v 1.1 2003/12/19 05:35:14 reinelt Exp $
+/* $Id: plugin.h,v 1.2 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin handler for the Evaluator
  *
  *
  *
  * $Log: plugin.h,v $
+ * Revision 1.2  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.1  2003/12/19 05:35:14  reinelt
  * renamed 'client' to 'plugin'
  *
@@ -44,5 +51,5 @@
 #define _PLUGIN_H_
 
 int plugin_init (void);
-
+void plugin_exit(void);
 #endif
index 0a9f9c6e120095be861908a7c75b4e4005b00103..cf81d10a1742bfe904801ad1535e0a29a9131164 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_cfg.c,v 1.5 2004/02/01 19:37:40 reinelt Exp $
+/* $Id: plugin_cfg.c,v 1.6 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for config file access
  *
  *
  *
  * $Log: plugin_cfg.c,v $
+ * Revision 1.6  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.5  2004/02/01 19:37:40  reinelt
  * got rid of every strtok() incarnation.
  *
@@ -87,13 +94,13 @@ static void load_variables (void)
     } else {
       expression=cfg_get_raw (section, l, "");
       if (expression!=NULL && *expression!='\0') {
-       if (Eval(expression, &result)==0) {
-         debug ("Variable %s = '%s' (%f)", l, R2S(&result), R2N(&result));
-         SetVariable (l, &result);
-         DelResult (&result);
-       } else {
-         error ("error evaluating variable '%s' from %s", list, cfg_source());
-       }
+        if (Eval(expression, &result)==0) {
+          debug ("Variable %s = '%s' (%f)", l, R2S(&result), R2N(&result));
+          SetVariable (l, &result);
+          DelResult (&result);
+        } else {
+          error ("error evaluating variable '%s' from %s", list, cfg_source());
+        }
       }
     }
     l=p?p+1:NULL;
@@ -127,12 +134,14 @@ static void my_cfg (RESULT *result, int argc, RESULT *argv[])
   
   // buffer starts with '.', so cut off first char
   value=cfg_get("", buffer+1, "");
-  
+    
+  // store result
+  SetResult(&result, R_STRING, value); 
+
   // free buffer again
   free (buffer);
   
-  // store result
-  SetResult(&result, R_STRING, value); 
+  free(value);
 }
 
 
@@ -146,3 +155,8 @@ int plugin_init_cfg (void)
   
   return 0;
 }
+
+void plugin_exit_cfg(void) 
+{
+       
+}
index e157a2eafec2f1ecc4f40bf876be6e66b88dfd74..1bec66b53ef8e38f541d949c34d543b790819c6e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_cpuinfo.c,v 1.7 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for /proc/cpuinfo parsing
  *
  *
  *
  * $Log: plugin_cpuinfo.c,v $
+ * Revision 1.8  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.7  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -143,3 +150,8 @@ int plugin_init_cpuinfo (void)
   AddFunction ("cpuinfo", 1, my_cpuinfo);
   return 0;
 }
+
+void plugin_exit_cpuinfo(void) 
+{
+       hash_destroy(&CPUinfo);
+}
index a834db1224f07cd1669a308d61c9a86c23bb8d4b..31780b8b1b2ae44ec357c18543ce14fb73484b0c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_dvb.c,v 1.2 2004/02/16 13:03:37 reinelt Exp $
+/* $Id: plugin_dvb.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for DVB status
  *
  *
  *
  * $Log: plugin_dvb.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/02/16 13:03:37  reinelt
  * compile problem with missing frontend.h fixed
  *
@@ -147,3 +154,7 @@ int plugin_init_dvb (void)
   return 0;
 }
 
+void plugin_exit_dvb(void) 
+{
+       hash_destroy(&DVB);
+}
index 812f6760f1a49aa0922e7c81bf33acb110abc92e..151ea96b3e028f079d088608c1f9608845fe09d0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_i2c_sensors.c,v 1.12 2004/02/16 08:19:44 reinelt Exp $
+/* $Id: plugin_i2c_sensors.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
  *
  * I2C sensors plugin
  *
  *
  *
  * $Log: plugin_i2c_sensors.c,v $
+ * Revision 1.13  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.12  2004/02/16 08:19:44  reinelt
  * i2c_sensors patch from Xavier
  *
@@ -368,8 +375,9 @@ int plugin_init_i2c_sensors (void)
     debug("if i2c_sensors doesn't work, double check this value !");
     path = realloc(path, strlen(path_cfg)+1);
     strcpy(path, path_cfg);
-    free(path_cfg);
+    
   }
+  free(path_cfg);
 
   // we activate the function only if there's a possibly path found
   if (path!=NULL) {
@@ -386,3 +394,8 @@ int plugin_init_i2c_sensors (void)
   
   return 0;
 }
+
+void plugin_exit_i2c_sensors(void) 
+{
+       hash_destroy(&I2Csensors);
+}
index a7aecc599f8673da9f3ff26914190a5c1d116326..b2ec22fb3dd871c605b4e64b66be6931d34d924b 100755 (executable)
@@ -1,4 +1,4 @@
-/* $Id: plugin_imon.c,v 1.2 2004/02/22 17:35:41 reinelt Exp $
+/* $Id: plugin_imon.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * imond/telmond data processing
  *
  *
  *
  * $Log: plugin_imon.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/02/22 17:35:41  reinelt
  * some fixes for generic graphic driver and T6963
  * removed ^M from plugin_imon (Nico, are you editing under Windows?)
@@ -36,6 +43,7 @@
 #include "plugin.h"
 #include "cfg.h"
 #include "hash.h"
+#include "qprintf.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -56,6 +64,7 @@
 #include <arpa/inet.h>                          /* decl of inet_addr()      */
 #include <sys/socket.h>
 
+
 static HASH TELMON = { 0, };
 static HASH IMON = { 0, };
 
@@ -246,7 +255,7 @@ static int parse_telmon(){
        hash_set (&TELMON, "time", time);
        date[4]='\0';
        date[7]='\0';
-       snprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
+       qprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
        hash_set (&TELMON, "number", number);
        hash_set (&TELMON, "msn", msn);
        hash_set (&TELMON, "date", time);
@@ -283,7 +292,7 @@ void init(){
   err++;
  } else if ((ipass!=NULL) && (*ipass!='\0')) { // Passwort senden
   char buf[40];
-  snprintf(buf,sizeof(buf),"pass %s",ipass);
+  qprintf(buf,sizeof(buf),"pass %s",ipass);
   send_command(fd,buf);
   get_answer(fd); 
  }
@@ -335,7 +344,7 @@ static int parse_imon_rates(char *channel){
  char *s;
  int age;
   
snprintf(buf,sizeof(buf),"rate %s in",channel);
qprintf(buf,sizeof(buf),"rate %s in",channel);
  
  // reread every half sec only
  age=hash_age(&IMON, buf, NULL);
@@ -345,14 +354,14 @@ static int parse_imon_rates(char *channel){
 
  if (err) return -1;
 
snprintf(buf, sizeof(buf), "rate %s", channel);
qprintf(buf, sizeof(buf), "rate %s", channel);
  s=get_value(buf);
  
  if (sscanf(s,"%s %s",in, out)!=2) return -1;
 
snprintf(buf, sizeof(buf), "rate %s in", channel);
qprintf(buf, sizeof(buf), "rate %s in", channel);
  hash_set (&IMON, buf , in);
snprintf(buf, sizeof(buf), "rate %s out", channel);
qprintf(buf, sizeof(buf), "rate %s out", channel);
  hash_set (&IMON, buf , out);
  
  return 0;
@@ -368,7 +377,7 @@ static void my_imon_rates (RESULT *result, RESULT *arg1, RESULT *arg2){
   return;
  }
  
snprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
qprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
 
  val=hash_get(&IMON, buf);
  if (val==NULL) val="";
@@ -397,6 +406,7 @@ int plugin_init_imon (void){
   telmon='\0';
  } 
  strcpy(thost,s);
+ free(s);
   
  if ((telmon=='\01') && (cfg_number("Telmon", "Port",5001,1,65536,&tport)<0)){
   error ("[Telmon] no valid port definition");
@@ -405,6 +415,7 @@ int plugin_init_imon (void){
  
  s=cfg_get ("Telmon", "Phonebook","/etc/phonebook");
  strcpy(phoneb,s);
+ free(s);
  
  s=cfg_get ("Imon", "Host", "127.0.0.1");
  if (*s=='\0') {
@@ -412,6 +423,7 @@ int plugin_init_imon (void){
   imon='\0';
  }
  strcpy(ihost,s); 
+ free(s);
  
  if ((imon=='\01') && (cfg_number("Imon", "Port",5000,1,65536,&iport)<0)){
   error ("[Imon] no valid port definition");
@@ -420,6 +432,7 @@ int plugin_init_imon (void){
  
  s=cfg_get ("Imon", "Pass", "");
  strcpy(ipass,s);
+ free(s);
        
  if (telmon=='\1') AddFunction ("telmon", 1, my_telmon);
  if (imon=='\1'){
@@ -430,3 +443,9 @@ int plugin_init_imon (void){
 
  return 0;
 }
+
+void plugin_exit_imon(void) 
+{
+       hash_destroy(&TELMON);
+       hash_destroy(&IMON);
+}
index 31601220e7cac85728501cbbbb4a16f7a9d7bc02..2c1749264988e6fd51455f1db081740d03c2d285 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_loadavg.c,v 1.3 2004/01/30 07:12:35 reinelt Exp $
+/* $Id: plugin_loadavg.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for load average
  *
  *
  *
  * $Log: plugin_loadavg.c,v $
+ * Revision 1.4  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.3  2004/01/30 07:12:35  reinelt
  * HD44780 busy-flag support from Martin Hejl
  * loadavg() uClibc replacement from Martin Heyl
@@ -59,6 +66,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 #include <fcntl.h>
 
 #include "debug.h"
@@ -104,14 +112,25 @@ int getloadavg (double loadavg[], int nelem)
 
 static void my_loadavg (RESULT *result, RESULT *arg1)
 {
-  int nelem, index;
-  double loadavg[3];
+  static int nelem;
+  int index,age;
+  static double loadavg[3];
+  static struct timeval last_value;
+  struct timeval now;
   
-  nelem=getloadavg(loadavg, 3);
-  if (nelem<0) {
-    error ("getloadavg() failed!");
-    SetResult(&result, R_STRING, "");
-    return;
+  gettimeofday(&now,NULL);
+  
+  age = (now.tv_sec - last_value.tv_sec)*1000 + (now.tv_usec - last_value.tv_usec)/1000;
+  // reread every 10 msec only
+  if (age==0 || age>10) {
+  
+    nelem=getloadavg(loadavg, 3);
+    if (nelem<0) {
+      error ("getloadavg() failed!");
+      SetResult(&result, R_STRING, "");
+      return;
+    }
+    last_value=now;
   }
 
   index=R2N(arg1);
@@ -120,6 +139,7 @@ static void my_loadavg (RESULT *result, RESULT *arg1)
     SetResult(&result, R_STRING, "");
     return;
   }
+
   
   SetResult(&result, R_NUMBER, &(loadavg[index-1]));
   return;
@@ -133,3 +153,6 @@ int plugin_init_loadavg (void)
   return 0;
 }
 
+void plugin_exit_loadavg(void) 
+{
+}
index 3d590861946d895a0c923c9dd15bc8f9aeb1a616..88e1f652932139fb492292786c08bad79298b383 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_math.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_math.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * math plugin
  *
  *
  *
  * $Log: plugin_math.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -131,3 +138,6 @@ int plugin_init_math (void)
   return 0;
 }
 
+void plugin_exit_math(void) 
+{
+}
index 0262258069a6a3ec1b5c333c12ae11ebc81ef217..fcc73a29e72099d62d9463d8f9b9c880ee5a8a6f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_meminfo.c,v 1.5 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_meminfo.c,v 1.6 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for /proc/meminfo parsing
  *
  *
  *
  * $Log: plugin_meminfo.c,v $
+ * Revision 1.6  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.5  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -136,3 +143,8 @@ int plugin_init_meminfo (void)
   return 0;
 }
 
+
+void plugin_exit_meminfo(void) 
+{
+       hash_destroy(&MemInfo);
+}
index 91b2edb202981ff132c4729ee109a58abd482f49..eb9673632ae69b75a102becfc63c7516ff07dc4f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_netdev.c,v 1.4 2004/02/15 07:23:04 reinelt Exp $
+/* $Id: plugin_netdev.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for /proc/net/dev parsing
  *
  *
  *
  * $Log: plugin_netdev.c,v $
+ * Revision 1.5  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.4  2004/02/15 07:23:04  reinelt
  * bug in netdev parsing fixed
  *
@@ -58,6 +65,7 @@
 #include "plugin.h"
 
 #include "hash.h"
+#include "qprintf.h"
 
 
 static HASH NetDev = { 0, };
@@ -67,7 +75,7 @@ static void hash_set3 (char *key1, char *key2, char *key3, char *val)
 {
   char key[32];
   
-  snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
+  qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
   hash_set_delta (&NetDev, key, val);
 }
 
@@ -161,3 +169,7 @@ int plugin_init_netdev (void)
   return 0;
 }
 
+void plugin_exit_netdev(void) 
+{
+       hash_destroy(&NetDev);
+}
index 7c3c64b0dd0d475af4947b204cacdb718732308b..e3c257ba4a1b061d5bf5fe8543980a241620fe8e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_ppp.c,v 1.2 2004/01/28 06:43:31 reinelt Exp $
+/* $Id: plugin_ppp.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for ppp throughput
  *
  *
  *
  * $Log: plugin_ppp.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/01/28 06:43:31  reinelt
  * plugin_ppp finished.
  *
@@ -56,7 +63,7 @@
 #include "debug.h"
 #include "plugin.h"
 #include "hash.h"
-
+#include "qprintf.h"
 
 #ifdef HAVE_NET_IF_PPP_H
 
@@ -87,7 +94,7 @@ static int get_ppp_stats (void)
   for (unit=0; unit<8; unit++) {
     memset (&req, 0, sizeof (req));
     req.stats_ptr = (caddr_t) &req.stats;
-    snprintf (req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit);
+    qprintf(req.ifr__name, sizeof(req.ifr__name), "ppp%d", unit);
     
     if (ioctl(fd, SIOCGPPPSTATS, &req) == 0) {
       ibytes=req.stats.p.ppp_ibytes;
@@ -95,11 +102,11 @@ static int get_ppp_stats (void)
     } else {
       ibytes=obytes=0;
     }
-    snprintf (key, sizeof(key), "Rx:%d", unit);
-    snprintf (val, sizeof(val), "%d", ibytes);
+    qprintf(key, sizeof(key), "Rx:%d", unit);
+    qprintf(val, sizeof(val), "%d", ibytes);
     hash_set_delta (&PPP, key, val);
-    snprintf (key, sizeof(key), "Tx:%d", unit);
-    snprintf (val, sizeof(val), "%d", obytes);
+    qprintf(key, sizeof(key), "Tx:%d", unit);
+    qprintf(val, sizeof(val), "%d", obytes);
     hash_set_delta (&PPP, key, val);
 
   }
@@ -130,3 +137,7 @@ int plugin_init_ppp (void)
   return 0;
 }
 
+void plugin_exit_ppp(void) 
+{
+       hash_destroy(&PPP);
+}
index f7276c4053e84b7ba32e24bd0c5cd50129c9adcf..d3b4815d9e1e9ec93c609c021780b96806dd452c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_proc_stat.c,v 1.15 2004/02/04 19:10:51 reinelt Exp $
+/* $Id: plugin_proc_stat.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for /proc/stat parsing
  *
  *
  *
  * $Log: plugin_proc_stat.c,v $
+ * Revision 1.16  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.15  2004/02/04 19:10:51  reinelt
  * Crystalfontz driver nearly finished
  *
 #include "debug.h"
 #include "plugin.h"
 #include "hash.h"
+#include "qprintf.h"
 
 
 static HASH Stat = { 0, };
@@ -111,7 +119,7 @@ static void hash_set2 (char *key1, char *key2, char *val)
 {
   char key[32];
   
-  snprintf (key, sizeof(key), "%s.%s", key1, key2);
+  qprintf(key, sizeof(key), "%s.%s", key1, key2);
   hash_set1 (key, val);
 }
 
@@ -120,7 +128,7 @@ static void hash_set3 (char *key1, char *key2, char *key3, char *val)
 {
   char key[32];
   
-  snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
+  qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
   hash_set1 (key, val);
 }
 
@@ -201,9 +209,9 @@ static int parse_proc_stat (void)
        while (strchr(delim, *beg)) beg++; 
        if ((end=strpbrk(beg, delim))) *end='\0'; 
        if (i==0) 
-         snprintf(num, sizeof(num), "sum");
+         strncpy(num,"sum",sizeof(num));
        else 
-         snprintf(num, sizeof(num), "%d", i-1);
+         qprintf(num, sizeof(num), "%d", i-1);
        hash_set2 ("intr", num,  beg);
        beg=end?end+1:NULL;
       }
@@ -328,7 +336,7 @@ static void my_disk (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3)
   key   = R2S(arg2);
   delay = R2N(arg3);
   
-  snprintf (buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
+  qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
   value  = hash_get_regex(&Stat, buffer, delay);
   
   SetResult(&result, R_NUMBER, &value); 
@@ -342,3 +350,8 @@ int plugin_init_proc_stat (void)
   AddFunction ("disk", 3, my_disk);
   return 0;
 }
+
+void plugin_exit_proc_stat(void) 
+{
+       hash_destroy(&Stat);
+}
index 30a7c84de42a2db79bdfe9e643d477fb1a0beaec..c570a792779f7d4c7462ce520f3707c43c71fca8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_sample.c,v 1.4 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: plugin_sample.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin template
  *
  *
  *
  * $Log: plugin_sample.c,v $
+ * Revision 1.5  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.4  2004/01/30 20:57:56  reinelt
  * HD44780 patch from Martin Hejl
  * dmalloc integrated
@@ -229,3 +236,7 @@ int plugin_init_sample (void)
   return 0;
 }
 
+void plugin_exit_sample(void) 
+{
+
+}
index 217aab029026547720d1bf943703c94e68683cb8..823fc0a6e3f9080ac6f1bae8e500f68a13767954 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_string.c,v 1.3 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_string.c,v 1.4 2004/03/03 03:47:04 reinelt Exp $
  *
  * string plugin
  *
  *
  *
  * $Log: plugin_string.c,v $
+ * Revision 1.4  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.3  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -69,3 +76,6 @@ int plugin_init_string (void)
   return 0;
 }
 
+void plugin_exit_string(void) 
+{
+}
index d8a05a03b31e0d2509dc4bd2c39f64663a5ab6ee..0967e77afd606b7f93ea089a72f0c4c30f01e2ee 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_uname.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_uname.c,v 1.3 2004/03/03 03:47:04 reinelt Exp $
  *
  * plugin for uname() syscall
  *
  *
  *
  * $Log: plugin_uname.c,v $
+ * Revision 1.3  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.2  2004/01/29 04:40:02  reinelt
  * every .c file includes "config.h" now
  *
@@ -98,3 +105,6 @@ int plugin_init_uname (void)
   return 0;
 }
 
+void plugin_exit_uname(void) 
+{
+}
index 400c55c76c008e808180782852afdbca1befc5b0..25d3add723aa0c3ffb913b7471e020ee685f5046 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: plugin_xmms.c,v 1.8 2004/02/05 23:58:18 mkeil Exp $
+/* $Id: plugin_xmms.c,v 1.9 2004/03/03 03:47:04 reinelt Exp $
  *
  * XMMS-Plugin for LCD4Linux
  * Copyright 2003 Markus Keil <markus_keil@t-online.de>
  *
  *
  * $Log: plugin_xmms.c,v $
+ * Revision 1.9  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.8  2004/02/05 23:58:18  mkeil
  * Fixed/Optimized Hashage-timings
  *
@@ -157,3 +164,8 @@ int plugin_init_xmms (void)
 
   return 0;
 }
+
+void plugin_exit_xmms(void) 
+{
+       hash_destroy(&xmms);
+}
diff --git a/seti.c b/seti.c
index e2d7c3673018ad3c31fb78a5d1264059d53e71a1..72332bf2f0da53343fd37e17a2ba76ad9404351a 100644 (file)
--- a/seti.c
+++ b/seti.c
@@ -1,4 +1,4 @@
-/* $Id: seti.c,v 1.13 2004/01/29 04:40:03 reinelt Exp $
+/* $Id: seti.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
  *
  * seti@home specific functions
  *
  *
  *
  * $Log: seti.c,v $
+ * Revision 1.14  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.13  2004/01/29 04:40:03  reinelt
  * every .c file includes "config.h" now
  *
@@ -123,16 +130,19 @@ int Seti (double *perc, double *cput)
     if (dir==NULL || *dir=='\0') {
       error ("no 'SetiDir' entry in %s!\n", cfg_source());
       fd=-1;
+      free(dir);
       return -1;
     }
     if (strlen(dir)>sizeof(fn)-sizeof(STATEFILE)-2) {
       error ("entry 'SetiDir' too long in %s!\n", cfg_source());
       fd=-1;
+      free(dir);
       return -1;
     }
     strcpy(fn, dir);
     strcat(fn, "/");
     strcat(fn, STATEFILE);
+    free(dir);
   }
 
   fd = open(fn, O_RDONLY);
diff --git a/timer.c b/timer.c
index 241aa4d2b0a5739f05928898976333638f8b6752..262a54386eefd1b232f492af7c3671049419ca2c 100644 (file)
--- a/timer.c
+++ b/timer.c
@@ -1,4 +1,4 @@
-/* $Id: timer.c,v 1.4 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: timer.c,v 1.5 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic timer handling
  *
  *
  *
  * $Log: timer.c,v $
+ * Revision 1.5  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.4  2004/01/30 20:57:56  reinelt
  * HD44780 patch from Martin Hejl
  * dmalloc integrated
@@ -187,3 +194,10 @@ int timer_process (struct timespec *delay)
   return 0;
   
 }
+
+void timer_exit() {
+  if (nTimers>0) {
+    nTimers=0;
+    free(Timers);;     
+  }
+}
diff --git a/timer.h b/timer.h
index d89f5d48fe6db7abc31b61e805e957838d75e6f5..80b5695197cda41edc6813e86734d3be0f2edcee 100644 (file)
--- a/timer.h
+++ b/timer.h
@@ -1,4 +1,4 @@
-/* $Id: timer.h,v 1.1 2004/01/13 08:18:20 reinelt Exp $
+/* $Id: timer.h,v 1.2 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic timer handling
  *
  *
  *
  * $Log: timer.h,v $
+ * Revision 1.2  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.1  2004/01/13 08:18:20  reinelt
  * timer queues added
  * liblcd4linux deactivated turing transformation to new layout
@@ -35,5 +42,5 @@
 
 int timer_add (void(*callback)(void *data), void *data, int interval, int one_shot);
 int timer_process (struct timespec *delay);
-
+void timer_exit();
 #endif
index e7ae1d349af964567dfaf1e3043619992a6089ce..2eaf240d9ec88aeb287ba7afe0ee66bc070ae40e 100644 (file)
--- a/widget.c
+++ b/widget.c
@@ -1,4 +1,4 @@
-/* $Id: widget.c,v 1.12 2004/02/18 06:39:20 reinelt Exp $
+/* $Id: widget.c,v 1.13 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic widget handling
  *
  *
  *
  * $Log: widget.c,v $
+ * Revision 1.13  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.12  2004/02/18 06:39:20  reinelt
  * T6963 driver for graphic displays finished
  *
@@ -129,6 +136,18 @@ int widget_register (WIDGET_CLASS *widget)
   return 0;
 }
 
+void widget_unregister(void) {
+  int i;
+  for (i=0;i<nWidgets;i++) {
+    Widgets[i].class->quit(&(Widgets[i]));
+  }
+  free(Widgets);
+
+  free(Classes);
+
+  nWidgets=0;
+  nClasses=0;
+}
 
 int widget_add (char *name, int row, int col)
 {
@@ -152,7 +171,7 @@ int widget_add (char *name, int row, int col)
     if (class) free (class);
     return -1;
   }
-  
+  free(section);
   // lookup widget class
   Class=NULL;
   for (i=0; i<nClasses; i++) {
index c1b2785fa22f648bade029aa9807c3b0ad8b146f..6fcfe116bfb85a845a9521dee1ee408a513f261c 100644 (file)
--- a/widget.h
+++ b/widget.h
@@ -1,4 +1,4 @@
-/* $Id: widget.h,v 1.7 2004/01/14 11:33:00 reinelt Exp $
+/* $Id: widget.h,v 1.8 2004/03/03 03:47:04 reinelt Exp $
  *
  * generic widget handling
  *
  *
  *
  * $Log: widget.h,v $
+ * Revision 1.8  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.7  2004/01/14 11:33:00  reinelt
  * new plugin 'uname' which does what it's called
  * text widget nearly finished
@@ -80,6 +87,7 @@ typedef struct WIDGET{
 
 
 int widget_register (WIDGET_CLASS *widget);
+void widget_unregister (void);
 int widget_add      (char *name, int row, int col);
 
 #endif
index 5e80e5cb78fd755868ad3448ef33d1db362d0aea..97bcaca86a534452000b7c276c5aefec46002375 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: widget_bar.c,v 1.7 2004/01/30 20:57:56 reinelt Exp $
+/* $Id: widget_bar.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
  *
  * bar widget handling
  *
  *
  *
  * $Log: widget_bar.c,v $
+ * Revision 1.8  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.7  2004/01/30 20:57:56  reinelt
  * HD44780 patch from Martin Hejl
  * dmalloc integrated
@@ -209,10 +216,9 @@ int widget_bar_init (WIDGET *Self)
 
 
 int widget_bar_quit (WIDGET *Self) {
-
-  if (Self->data) {
-    free (Self->data);
-    Self->data=NULL;
+  if (Self ) {
+         if (Self->data) free(Self->data);
+      Self->data=NULL;
   }
   
   return 0;
index a8d97383fdb89d079a57edd47664688148c59492..6a6ad6bf5b07b660a8f202fd0f164f1c3acd6499 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: widget_icon.c,v 1.7 2004/02/15 21:43:43 reinelt Exp $
+/* $Id: widget_icon.c,v 1.8 2004/03/03 03:47:04 reinelt Exp $
  *
  * icon widget handling
  *
  *
  *
  * $Log: widget_icon.c,v $
+ * Revision 1.8  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.7  2004/02/15 21:43:43  reinelt
  * T6963 driver nearly finished
  * framework for graphic displays done
@@ -70,6 +77,7 @@
 #include "timer.h"
 #include "widget.h"
 #include "widget_icon.h"
+#include "qprintf.h"
 
 #ifdef WITH_DMALLOC
 #include <dmalloc.h>
@@ -86,7 +94,7 @@ static void widget_icon_read_bitmap (char *section, WIDGET_ICON *Icon)
   unsigned char *map;
   
   for (row=0; row<YRES; row++) {
-    snprintf (key, sizeof(key), "Bitmap.Row%d", row+1);
+    qprintf(key, sizeof(key), "Bitmap.Row%d", row+1);
     val=cfg_get(section, key, ""); 
     map=Icon->bitmap+row;
     n=0;
@@ -110,6 +118,7 @@ static void widget_icon_read_bitmap (char *section, WIDGET_ICON *Icon)
        (*map)<<=1;
       }
     }
+    free(val);
   }
 }
 
@@ -203,12 +212,15 @@ int widget_icon_init (WIDGET *Self)
 
 int widget_icon_quit (WIDGET *Self) 
 {
-  WIDGET_ICON *Icon = Self->data;
+  WIDGET_ICON *Icon;
   
-  if (Self->data) {
-    if (Icon->bitmap) free (Icon->bitmap); 
-    free (Self->data);
-    Self->data=NULL;
+  if (Self) {
+       Icon = Self->data;
+    if (Icon) {
+      if (Icon->bitmap) free (Icon->bitmap); 
+      free(Self->data);
+      Self->data=NULL;
+    }
   }
   
   return 0;
index a936febb1185678a731451586cec8bb530243e2f..3b413fcd2e8431db8e07e58423c3fda1efad84de 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: widget_text.c,v 1.13 2004/02/18 06:39:20 reinelt Exp $
+/* $Id: widget_text.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $
  *
  * simple text widget handling
  *
  *
  *
  * $Log: widget_text.c,v $
+ * Revision 1.14  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.13  2004/02/18 06:39:20  reinelt
  * T6963 driver for graphic displays finished
  *
@@ -381,12 +388,18 @@ int widget_text_init (WIDGET *Self)
 
 
 int widget_text_quit (WIDGET *Self) {
-
-  if (Self->data) {
-    free (Self->data);
-    Self->data=NULL;
+  WIDGET_TEXT *Text;
+  if (Self) {
+    Text=Self->data;
+    if (Self->data) {    
+      if (Text->preval)      free(Text->preval);
+      if (Text->postval)     free(Text->postval);
+      if (Text->value)       free(Text->value);
+      if (Text->buffer)      free(Text->buffer);
+      free (Self->data);
+      Self->data=NULL;
+    }
   }
-  
   return 0;
   
 }
diff --git a/wifi.c b/wifi.c
index 5693e795e6eea8e32aefb88ea85d13b5168494cb..9d13d73b1b783b59fbb7bdbb4213f28857e4b3a6 100644 (file)
--- a/wifi.c
+++ b/wifi.c
@@ -1,4 +1,4 @@
-/* $Id: wifi.c,v 1.6 2004/01/29 04:40:03 reinelt Exp $
+/* $Id: wifi.c,v 1.7 2004/03/03 03:47:04 reinelt Exp $
  *
  * WIFI specific functions
  *
  *
  *
  * $Log: wifi.c,v $
+ * Revision 1.7  2004/03/03 03:47:04  reinelt
+ * big patch from Martin Hejl:
+ * - use qprintf() where appropriate
+ * - save CPU cycles on gettimeofday()
+ * - add quit() functions to free allocated memory
+ * - fixed lots of memory leaks
+ *
  * Revision 1.6  2004/01/29 04:40:03  reinelt
  * every .c file includes "config.h" now
  *
@@ -139,5 +146,6 @@ int Wifi (int *signal, int *link, int *noise)
   *signal=ws;
   *link=wl;
   *noise=wn;
+  free(interface);
   return 0; 
 }