aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Raster.c32
-rw-r--r--Text.c17
-rw-r--r--cfg.c22
-rw-r--r--drv_HD44780.c27
-rw-r--r--drv_generic_graphic.c8
-rw-r--r--drv_generic_parport.c20
-rw-r--r--drv_generic_serial.c17
-rw-r--r--drv_generic_text.c12
-rw-r--r--evaluator.c52
-rw-r--r--evaluator.h11
-rw-r--r--exec.c23
-rw-r--r--hash.c35
-rw-r--r--hash.h13
-rwxr-xr-ximon.c37
-rw-r--r--layout.c14
-rw-r--r--lcd4linux.c23
-rw-r--r--lock.c16
-rw-r--r--mail.c27
-rw-r--r--mail2.c15
-rw-r--r--pid.c15
-rw-r--r--plugin.c44
-rw-r--r--plugin.h11
-rw-r--r--plugin_cfg.c36
-rw-r--r--plugin_cpuinfo.c14
-rw-r--r--plugin_dvb.c13
-rw-r--r--plugin_i2c_sensors.c17
-rwxr-xr-xplugin_imon.c35
-rw-r--r--plugin_loadavg.c39
-rw-r--r--plugin_math.c12
-rw-r--r--plugin_meminfo.c14
-rw-r--r--plugin_netdev.c16
-rw-r--r--plugin_ppp.c25
-rw-r--r--plugin_proc_stat.c25
-rw-r--r--plugin_sample.c13
-rw-r--r--plugin_string.c12
-rw-r--r--plugin_uname.c12
-rw-r--r--plugin_xmms.c14
-rw-r--r--seti.c12
-rw-r--r--timer.c16
-rw-r--r--timer.h11
-rw-r--r--widget.c23
-rw-r--r--widget.h10
-rw-r--r--widget_bar.c16
-rw-r--r--widget_icon.c26
-rw-r--r--widget_text.c25
-rw-r--r--wifi.c10
46 files changed, 770 insertions, 167 deletions
diff --git a/Raster.c b/Raster.c
index b0587a6..0bf1b91 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 f318c73..9499b0d 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 5fb0087..dd6d2c3 100644
--- 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
*
@@ -23,6 +23,13 @@
*
*
* $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);
}
diff --git a/drv_HD44780.c b/drv_HD44780.c
index 62b5e3b..f30f0c7 100644
--- a/drv_HD44780.c
+++ b/drv_HD44780.c
@@ -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
*
@@ -29,6 +29,13 @@
*
*
* $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
diff --git a/drv_generic_graphic.c b/drv_generic_graphic.c
index d7968f7..c51e22e 100644
--- a/drv_generic_graphic.c
+++ b/drv_generic_graphic.c
@@ -23,6 +23,13 @@
*
*
* $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);
}
diff --git a/drv_generic_parport.c b/drv_generic_parport.c
index 68d537f..c9aac3d 100644
--- a/drv_generic_parport.c
+++ b/drv_generic_parport.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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 {
diff --git a/drv_generic_serial.c b/drv_generic_serial.c
index 46c524d..a4cb312 100644
--- a/drv_generic_serial.c
+++ b/drv_generic_serial.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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'
@@ -94,6 +101,7 @@
#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;
}
diff --git a/drv_generic_text.c b/drv_generic_text.c
index 60b7875..3fd5666 100644
--- a/drv_generic_text.c
+++ b/drv_generic_text.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
}
diff --git a/evaluator.c b/evaluator.c
index 17fee4c..7700c5a 100644
--- a/evaluator.c
+++ b/evaluator.c
@@ -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
*
@@ -10,6 +10,13 @@
* 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);
}
diff --git a/evaluator.h b/evaluator.h
index 9ace102..35e2981 100644
--- a/evaluator.h
+++ b/evaluator.h
@@ -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
*
@@ -10,6 +10,13 @@
* 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 b64653f..194641d 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 0167466..f263e8a 100644
--- 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)
*
@@ -23,6 +23,13 @@
*
*
* $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
*
@@ -101,6 +108,24 @@
#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 cefdc50..1130661 100644
--- 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)
*
@@ -23,6 +23,13 @@
*
*
* $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 bd329b9..40a52b8 100755
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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;
diff --git a/layout.c b/layout.c
index 451d80a..312e1ef 100644
--- 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
*
@@ -23,6 +23,13 @@
*
*
* $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;
}
diff --git a/lcd4linux.c b/lcd4linux.c
index 764f67e..5d73d34 100644
--- a/lcd4linux.c
+++ b/lcd4linux.c
@@ -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
*
@@ -22,6 +22,13 @@
*
*
* $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 f7f42de..b03a555 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 40a10fe..68f29b6 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 4de52ad..63cc604 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 bdf7737..743470a 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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);
diff --git a/plugin.c b/plugin.c
index 7e1c36b..0dc4e54 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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();
+}
diff --git a/plugin.h b/plugin.h
index d860c31..61a9aa0 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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
diff --git a/plugin_cfg.c b/plugin_cfg.c
index 0a9f9c6..cf81d10 100644
--- a/plugin_cfg.c
+++ b/plugin_cfg.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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)
+{
+
+}
diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c
index e157a2e..1bec66b 100644
--- a/plugin_cpuinfo.c
+++ b/plugin_cpuinfo.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_dvb.c b/plugin_dvb.c
index a834db1..31780b8 100644
--- a/plugin_dvb.c
+++ b/plugin_dvb.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_i2c_sensors.c b/plugin_i2c_sensors.c
index 812f676..151ea96 100644
--- a/plugin_i2c_sensors.c
+++ b/plugin_i2c_sensors.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_imon.c b/plugin_imon.c
index a7aecc5..b2ec22f 100755
--- a/plugin_imon.c
+++ b/plugin_imon.c
@@ -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
*
@@ -22,6 +22,13 @@
*
*
* $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);
+}
diff --git a/plugin_loadavg.c b/plugin_loadavg.c
index 3160122..2c17492 100644
--- a/plugin_loadavg.c
+++ b/plugin_loadavg.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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)
+{
+}
diff --git a/plugin_math.c b/plugin_math.c
index 3d59086..88e1f65 100644
--- a/plugin_math.c
+++ b/plugin_math.c
@@ -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
*
@@ -22,6 +22,13 @@
*
*
* $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)
+{
+}
diff --git a/plugin_meminfo.c b/plugin_meminfo.c
index 0262258..fcc73a2 100644
--- a/plugin_meminfo.c
+++ b/plugin_meminfo.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_netdev.c b/plugin_netdev.c
index 91b2edb..eb96736 100644
--- a/plugin_netdev.c
+++ b/plugin_netdev.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_ppp.c b/plugin_ppp.c
index 7c3c64b..e3c257b 100644
--- a/plugin_ppp.c
+++ b/plugin_ppp.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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);
+}
diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c
index f7276c4..d3b4815 100644
--- a/plugin_proc_stat.c
+++ b/plugin_proc_stat.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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
*
@@ -97,6 +104,7 @@
#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);
+}
diff --git a/plugin_sample.c b/plugin_sample.c
index 30a7c84..c570a79 100644
--- a/plugin_sample.c
+++ b/plugin_sample.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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)
+{
+
+}
diff --git a/plugin_string.c b/plugin_string.c
index 217aab0..823fc0a 100644
--- a/plugin_string.c
+++ b/plugin_string.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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)
+{
+}
diff --git a/plugin_uname.c b/plugin_uname.c
index d8a05a0..0967e77 100644
--- a/plugin_uname.c
+++ b/plugin_uname.c
@@ -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
*
@@ -23,6 +23,13 @@
*
*
* $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)
+{
+}
diff --git a/plugin_xmms.c b/plugin_xmms.c
index 400c55c..25d3add 100644
--- a/plugin_xmms.c
+++ b/plugin_xmms.c
@@ -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>
@@ -21,6 +21,13 @@
*
*
* $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 e2d7c36..72332bf 100644
--- 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
*
@@ -22,6 +22,13 @@
*
*
* $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 241aa4d..262a543 100644
--- 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
*
@@ -21,6 +21,13 @@
*
*
* $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 d89f5d4..80b5695 100644
--- 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
*
@@ -23,6 +23,13 @@
*
*
* $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
diff --git a/widget.c b/widget.c
index e7ae1d3..2eaf240 100644
--- 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
*
@@ -21,6 +21,13 @@
*
*
* $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++) {
diff --git a/widget.h b/widget.h
index c1b2785..6fcfe11 100644
--- 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
*
@@ -23,6 +23,13 @@
*
*
* $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
diff --git a/widget_bar.c b/widget_bar.c
index 5e80e5c..97bcaca 100644
--- a/widget_bar.c
+++ b/widget_bar.c
@@ -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
*
@@ -21,6 +21,13 @@
*
*
* $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;
diff --git a/widget_icon.c b/widget_icon.c
index a8d9738..6a6ad6b 100644
--- a/widget_icon.c
+++ b/widget_icon.c
@@ -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
*
@@ -21,6 +21,13 @@
*
*
* $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;
diff --git a/widget_text.c b/widget_text.c
index a936feb..3b413fc 100644
--- a/widget_text.c
+++ b/widget_text.c
@@ -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
*
@@ -21,6 +21,13 @@
*
*
* $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 5693e79..9d13d73 100644
--- 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
*
@@ -25,6 +25,13 @@
*
*
* $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;
}