aboutsummaryrefslogtreecommitdiffstats
path: root/cpulist.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpulist.c')
-rw-r--r--cpulist.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/cpulist.c b/cpulist.c
index dfb4733..eb219b5 100644
--- a/cpulist.c
+++ b/cpulist.c
@@ -16,11 +16,15 @@ extern struct s_cpudata cpudata;
// Add a CPU to the list
void cpulist_add(char *cpu)
{
- cpudata.cpulist_len++;
- cpudata.cpulist=reallocarray(cpudata.cpulist,cpudata.cpulist_len,sizeof(char *));
- cpudata.cpulist[cpudata.cpulist_len-1]=malloc(strlen(cpu)+1);
- strcpy(cpudata.cpulist[cpudata.cpulist_len-1],cpu);
- cpudata.cpulist[cpudata.cpulist_len-1][strlen(cpu)]=0;
+ int newlen;
+
+ newlen=cpudata.cpulist_len+1;
+ cpudata.cpulist=reallocarray(cpudata.cpulist,newlen,sizeof(char *));
+
+ cpudata.cpulist[cpudata.cpulist_len]=malloc(strlen(cpu)+1);
+ strcpy(cpudata.cpulist[cpudata.cpulist_len],cpu);
+ cpudata.cpulist[cpudata.cpulist_len][strlen(cpu)]=0;
+ cpudata.cpulist_len=newlen;
}
// Validate if we found a file named cpu[0-9][0-9][0-9]
@@ -101,10 +105,10 @@ void cpulist_free()
{
int count;
if (cpudata.cpulist==NULL) return;
+ int len=cpudata.cpulist_len;
+ cpudata.cpulist_len=0;
- for(count=0;count<cpudata.cpulist_len;count++) free(cpudata.cpulist[count]);
-
+ for(count=0;count<len;count++) free(cpudata.cpulist[count]);
free(cpudata.cpulist);
cpudata.cpulist=NULL;
- cpudata.cpulist_len=0;
}