Citeren Tim Rice <[email protected]>:
This may be the least intrusive way to fix it. ------------------------------ --- nut-svn/drivers/bcmxcp.c.old 2009-12-15 09:32:45.000000000 -0800 +++ nut-svn/drivers/bcmxcp.c 2009-12-15 14:03:34.602495008 -0800 @@ -871,13 +871,14 @@int init_outlet(unsigned char len) { - unsigned char answer[len]; + unsigned char *answer; int iIndex = 0, res, num; int num_outlet, size_outlet; int outlet_num, outlet_state; short auto_dly_off, auto_dly_on; char outlet_name[25]; + answer = xmalloc((size_t) len); res = command_read_sequence(PW_OUT_MON_BLOCK_REQ, answer); if (res <= 0) fatal_with_errno(EXIT_FAILURE, "Could not communicate with the ups");
Close, but no cigar. Since init_outlet() can also be called from upsdrv_initinfo(), this change will leak memory. You need to vall free(answer) to de-allocate the memory before leaving init_outlet().
When changing something in dynamic memory allocation, running 'valgrind' is mandatory to check for leaks. While this isn't a 100% guarantee that there are no memory leaks (they may not get triggered), this will usually spot the most obvious ones like the above.
Best regards, Arjen -- Please keep list traffic on the list _______________________________________________ Nut-upsdev mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev
