20 Aug, 2015, arholly wrote in the 1st comment:
Votes: 0
Hi there:
So, I realized that I've got a memory leak but I'm not at all the familiar with memory. I know I need to free it and based on what I've seen in the code, I have some idea of how it works, but not a whole lot. I'm guessing that the free I wrote isn't accurate, but I'm entirely sure what I'm doing, so if someone could help explain it, that would be awesome.

Thanks in advance,
Arholly

void add_poll(int pnum, char *question, sbyte active, sbyte revote)
{
poll_list[pnum].title = strdup(question);
poll_list[pnum].active = active;
poll_list[pnum].revote = revote;
poll_list[pnum].options[0] = strdup("\r\n");
}

void free_poll(void)
{
free(poll_list[pnum].title);
free(poll_list[pnum].options[0]);
}
20 Aug, 2015, Davion wrote in the 2nd comment:
Votes: 1
arholly said:
Hi there:
So, I realized that I've got a memory leak but I'm not at all the familiar with memory. I know I need to free it and based on what I've seen in the code, I have some idea of how it works, but not a whole lot. I'm guessing that the free I wrote isn't accurate, but I'm entirely sure what I'm doing, so if someone could help explain it, that would be awesome.

Thanks in advance,
Arholly

void add_poll(int pnum, char *question, sbyte active, sbyte revote)
{
poll_list[pnum].title = strdup(question);
poll_list[pnum].active = active;
poll_list[pnum].revote = revote;
poll_list[pnum].options[0] = strdup("\r\n");
}

void free_poll(void)
{
free(poll_list[pnum].title);
free(poll_list[pnum].options[0]);
}


As far as I can tell, your code frees correctly. The only problem is void free_poll() accepts no arguments and the function is expected to know what pnum is.

With regards to freeing, something that you use strdup(), calloc(), malloc(), or realloc() to set will need to be free'd.
22 Aug, 2015, arholly wrote in the 3rd comment:
Votes: 0
Davion said:
As far as I can tell, your code frees correctly. The only problem is void free_poll() accepts no arguments and the function is expected to know what pnum is.

With regards to freeing, something that you use strdup(), calloc(), malloc(), or realloc() to set will need to be free'd.

Ok, so how should I then write it so that I can use it to free up the polls? This is one of those things I'm unsure of. I've tried using it like:
void free_poll(int pnum)
{
free(poll_list[pnum].title);
free(poll_list[pnum].options[0]);
}

and then dropping free_poll(); but I quickly figure out that isn't write. So, what am I doing wrong (preferably with an explanation).
22 Aug, 2015, Tyche wrote in the 4th comment:
Votes: 0
Maybe an array isn't the best structure here.
0.0/4