diff --git a/AUTHORS b/AUTHORS index 9cf80975..8e27fe8a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -62,6 +62,9 @@ Dave Clark David McCabe utime +garo + gw_iface fix + Ram Yalamanchili tztime diff --git a/ChangeLog b/ChangeLog index e9047363..78eca40f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ # $Id$ +2008-06-04 + * Fix bug where conky tries to free a already freed pointer when you + use gw_iface with a empty routingtable in linux + 2008-06-03 * Added NVIDIA Graficcard support patch (thanks meissna) * Added --quiet patch (thanks sceptik) diff --git a/src/linux.c b/src/linux.c index 9baffff4..4576c93d 100644 --- a/src/linux.c +++ b/src/linux.c @@ -261,6 +261,16 @@ END_TRUE: x = strndup(y, text_buffer_size); \ } +void update_gateway_info_failure(char *reason) +{ + if(reason != NULL) { + perror(reason); + } + //2 pointers to 1 location causes a crash when we try to free them both + info.gw_info.iface = strndup("failed", text_buffer_size); + info.gw_info.ip = strndup("failed", text_buffer_size); +} + void update_gateway_info(void) { FILE *fp; @@ -277,14 +287,13 @@ void update_gateway_info(void) gw_info->count = 0; if ((fp = fopen("/proc/net/route", "r")) == NULL) { - perror("fopen()"); - info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size); - return; + update_gateway_info_failure("fopen()"); + return; } if (fscanf(fp, "%*[^\n]\n") == EOF) { - perror("fscanf()"); + //NULL because a empty table is not a error + update_gateway_info_failure(NULL); fclose(fp); - info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size); return; } while (!feof(fp)) { @@ -292,9 +301,8 @@ void update_gateway_info(void) if(fscanf(fp, "%63s %lx %lx %x %hd %hd %hd %lx %hd %hd %hd\n", iface, &dest, &gate, &flags, &ref, &use, &metric, &mask, &mtu, &win, &irtt) != 11) { - perror("fscanf()"); + update_gateway_info_failure("fscanf()"); fclose(fp); - info.gw_info.iface = info.gw_info.ip = strndup("failed", text_buffer_size); return; } if (flags & RTF_GATEWAY && dest == 0 && mask == 0) {