[Nut-upsdev] 1) A memory leak in drivers/rhino.c 2) Wunused-but-set-variable.patch
Regid Ichira
regid23 at yahoo.com
Thu Oct 13 22:11:44 UTC 2011
I would like to have your comments regarding:
1) drivers/rhino.c
------------------
The following patch addresses some problems in drivers/rhino.c. Or
that is what I think. I don't use this hardware. The patch:
1. Eliminates some usefulness definitions.
2. It removes code that evaluate the time. I can't see how the code
actually does useful work.
3. The evaluation time code allocates memory. I don't see how that
memory is freed.
Index: b/drivers/rhino.c
===================================================================
--- a/drivers/rhino.c 2011-10-12 03:16:00.000000000 +0300
+++ b/drivers/rhino.c 2011-10-12 12:24:46.000000000 +0300
@@ -85,12 +85,6 @@ static double const FA = -2; /*
static double const ConstInt = 250; /* Consumo interno sem o carregador */
static double const Vin = 220; /* Tensão de entrada */
-static int Day, Month, Year;
-static int dian=0, mesn=0, anon=0, weekn=0;
-static int ihour,imin, isec;
-/* unsigned char DaysOnWeek; */
-/* char seman[4]; */
-
/* int FExpansaoBateria; */
/* internal variables */
/* package handshake variables */
@@ -142,19 +136,9 @@ static unsigned char RecPack[37];
#ifdef PORTUGUESE
#define M_UNKN "Modêlo rhino desconhecido\n"
#define NO_RHINO "Rhino não detectado! abortando ...\n"
-#define UPS_DATE "Data no UPS %4d/%02d/%02d\n"
-#define SYS_DATE "Data do Sistema %4d/%02d/%02d dia da semana %s\n"
-#define ERR_PACK "Pacote errado\n"
-#define NO_EVENT "Não há eventos\n"
-#define UPS_TIME "Hora interna UPS %0d:%02d:%02d\n"
#else
#define M_UNKN "Unknown rhino model\n"
#define NO_RHINO "Rhino not detected! aborting ...\n"
-#define UPS_DATE "UPS Date %4d/%02d/%02d\n"
-#define SYS_DATE "System Date %4d/%02d/%02d day of week %s\n"
-#define ERR_PACK "Wrong package\n"
-#define NO_EVENT "No events\n"
-#define UPS_TIME "UPS internal Time %0d:%02d:%02d\n"
#endif
static int
@@ -204,14 +188,14 @@ ScanReceivePack( void )
/* model independent data */
- Year = RecPack[31] + ( RecPack[32] * 100 );
- Month = RecPack[30];
- Day = RecPack[29];
+ /* Year = RecPack[31] + ( RecPack[32] * 100 ); */
+ /* Month = RecPack[30]; */
+ /* Day = RecPack[29]; */
/* UPS internal time */
- ihour = RecPack[26];
- imin = RecPack[27];
- isec = RecPack[28];
+ /* ihour = RecPack[26]; */
+ /* imin = RecPack[27]; */
+ /* isec = RecPack[28]; */
/* Flag1 */
/* SobreTemp = ( ( 0x01 & RecPack[33]) = 0x01 ); */
@@ -546,18 +530,8 @@ static void getbaseinfo(void)
unsigned char temp[256];
unsigned char Pacote[37];
int tam, i, j=0;
- time_t *tmt;
- struct tm *now;
const char *Model;
- tmt = ( time_t * ) malloc( sizeof( time_t ) );
- time( tmt );
- now = localtime( tmt );
- dian = now->tm_mday;
- mesn = now->tm_mon+1;
- anon = now->tm_year+1900;
- weekn = now->tm_wday;
-
/* trying detect rhino model */
while ( ( !detected ) && ( j < 10 ) )
{
@@ -644,14 +618,6 @@ static void getupdateinfo(void)
unsigned char temp[256];
int tam;
- /* time update */
- time_t *tmt;
- struct tm *now;
- tmt = ( time_t * ) malloc( sizeof( time_t ) );
- time( tmt );
- now = localtime( tmt );
- /* int hours, mins; hours = now->tm_hour; mins = now->tm_min; */
-
temp[0] = 0; /* flush temp buffer */
tam = ser_get_buf_len(upsfd, temp, pacsize, 3, 0);
2) nut-upsdev/2011-October/005608.html
--------------------------------------
The patch from above might not apply cleanly. The reason is that I
first applied the patch from nut-upsdev/2011-October/005608.html.
That patch deals with another issue I see in the rhino.c driver, as
well as other files. According to the changelog, the part of it
concerns drivers/bestfcom.c was applied on 2011-07-13 to [r3132]. Yet
it concerns more files. Although it were not applied to the other
files, no one express any opinion why it should not get applied.
More information about the Nut-upsdev
mailing list