mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-17 10:35:10 +00:00
Assorted fixes found by valgrind
== common.cc == 'result' can be uninitialized. == conky.cc == strcpy()'s overlap: undefined behaviour. memmove()'s one is defined. == eve.cc == Some simplifications, and there are two leaks: 1. 'mySkill' could be leaked. So, let's make 'skill' point to it instead of strdup()'ing the buffer. 2. 'output' could be leaked at l.390. == freebsd.cc == Leak of 'freq_sysctl'. == net_stat.cc == free() already null-checks, so we don't need to do it again. == proc.cc == Leak. Signed-off-by: Pavel Labath <pavelo@centrum.sk>
This commit is contained in:
parent
c08b8bbee7
commit
622bf0cd7e
@ -594,13 +594,13 @@ static int check_contains(char *f, char *s)
|
||||
int if_existing_iftest(struct text_object *obj)
|
||||
{
|
||||
char *spc;
|
||||
int result;
|
||||
int result = 0;
|
||||
|
||||
spc = strchr(obj->data.s, ' ');
|
||||
if(spc != NULL) *spc = 0;
|
||||
if (access(obj->data.s, F_OK) == 0) {
|
||||
if(spc == NULL || check_contains(obj->data.s, spc + 1)) result = 1;
|
||||
} else result = 0;
|
||||
}
|
||||
if(spc != NULL) *spc = ' ';
|
||||
return result;
|
||||
}
|
||||
|
@ -1007,7 +1007,7 @@ static int get_string_width_special(char *s, int special_index)
|
||||
if(current_after_font->type == FONT) {
|
||||
influenced_by_font[i]=0;
|
||||
break;
|
||||
} else strcpy(&influenced_by_font[i], &influenced_by_font[i+1]);
|
||||
} else memmove(&influenced_by_font[i], &influenced_by_font[i+1], strlen(&influenced_by_font[i+1]) + 1);
|
||||
}
|
||||
}
|
||||
//add the length of influenced_by_font in the new font to width
|
||||
@ -1019,7 +1019,8 @@ static int get_string_width_special(char *s, int special_index)
|
||||
//make sure there chars counted in the new font are not again counted in the old font
|
||||
int specials_skipped=0;
|
||||
while(i>0) {
|
||||
if(p[specials_skipped]!=1) strcpy(&p[specials_skipped], &p[specials_skipped+1]); else specials_skipped++;
|
||||
if(p[specials_skipped]!=1) memmove(&p[specials_skipped], &p[specials_skipped+1], strlen(&p[specials_skipped+1]) + 1);
|
||||
else specials_skipped++;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
17
src/eve.cc
17
src/eve.cc
@ -291,13 +291,12 @@ static char *getSkillname(const char *file, int skillid)
|
||||
for (r = q->children; r; r = r->next) {
|
||||
xmlElementPtr ele = (xmlElementPtr) r;
|
||||
xmlAttrPtr attr = (xmlAttrPtr) ele->attributes;
|
||||
char *mySkill;
|
||||
int id, assigned = 0;
|
||||
char *mySkill = NULL;
|
||||
int id;
|
||||
|
||||
while (attr != NULL) {
|
||||
if (!strcasecmp((const char *)attr->name, "typeName")) {
|
||||
mySkill = strdup((const char *)attr->children->content);
|
||||
assigned = 1;
|
||||
} else if (!strcasecmp((const char *)attr->name, "typeID")) {
|
||||
id = atoi((const char *)attr->children->content);
|
||||
}
|
||||
@ -305,12 +304,11 @@ static char *getSkillname(const char *file, int skillid)
|
||||
}
|
||||
|
||||
if (id == skillid) {
|
||||
skill = strdup(mySkill);
|
||||
/* free(mySkill); */
|
||||
skill = mySkill;
|
||||
goto END;
|
||||
}
|
||||
if (assigned)
|
||||
free(mySkill);
|
||||
|
||||
free(mySkill);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,12 +377,10 @@ static char *eve(char *userid, char *apikey, char *charid)
|
||||
}
|
||||
|
||||
if (parseTrainingXml(content, chr)) {
|
||||
output = (char *)malloc(200 * sizeof(char));
|
||||
sprintf(output, "API error");
|
||||
output = strdup("API error");
|
||||
return output;
|
||||
}
|
||||
|
||||
output = (char *)malloc(200 * sizeof(char));
|
||||
timel = formatTime(&chr->ends);
|
||||
old_umask = umask(0066);
|
||||
tmp_fd = mkstemp(skillfile);
|
||||
@ -398,6 +394,7 @@ static char *eve(char *userid, char *apikey, char *charid)
|
||||
|
||||
chr->skillname = strdup(skill);
|
||||
|
||||
output = (char *)malloc(200 * sizeof(char));
|
||||
sprintf(output, EVE_OUTPUT_FORMAT, chr->skillname, chr->level, timel);
|
||||
free(skill);
|
||||
return output;
|
||||
|
@ -580,6 +580,11 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
|
||||
int freq;
|
||||
char *freq_sysctl;
|
||||
|
||||
if (!p_client_buffer || client_buffer_size <= 0 || !p_format
|
||||
|| divisor <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
freq_sysctl = (char *) calloc(16, sizeof(char));
|
||||
if (freq_sysctl == NULL) {
|
||||
exit(-1);
|
||||
@ -587,11 +592,6 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
|
||||
|
||||
snprintf(freq_sysctl, 16, "dev.cpu.%d.freq", (cpu - 1));
|
||||
|
||||
if (!p_client_buffer || client_buffer_size <= 0 || !p_format
|
||||
|| divisor <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (GETSYSCTL(freq_sysctl, freq) == 0) {
|
||||
snprintf(p_client_buffer, client_buffer_size, p_format,
|
||||
(float) freq / divisor);
|
||||
|
@ -507,8 +507,7 @@ void free_dns_data(struct text_object *obj)
|
||||
|
||||
for (i = 0; i < dns_data.nscount; i++)
|
||||
free(dns_data.ns_list[i]);
|
||||
if (dns_data.ns_list)
|
||||
free(dns_data.ns_list);
|
||||
free(dns_data.ns_list);
|
||||
memset(&dns_data, 0, sizeof(dns_data));
|
||||
}
|
||||
|
||||
|
@ -191,9 +191,9 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
free(var);
|
||||
*p = 0;
|
||||
}
|
||||
free(var);
|
||||
}
|
||||
|
||||
void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
||||
|
Loading…
Reference in New Issue
Block a user