Re: [cc65] Why crashing attempting to free this struct?

From: Payton Byrd <plbyrd1gmail.com>
Date: 2012-03-26 20:31:48
On Sat, Mar 24, 2012 at 8:09 PM, Payton Byrd <plbyrd@gmail.com> wrote:

>
>
> On Sat, Mar 24, 2012 at 8:07 PM, Christopher Pow <
> christopher.s.pow@gmail.com> wrote:
>
>> > I get a CPU jam whenever I attempt to free an instance of
>> > DirectoryListReuBlock.  I've got no idea what's causing this, but they
>> have
>> > to be freed or I'll have memory leaks galore.
>>
>> Probably would have to see more of the code to be able to help...
>>
>
> Here's the code for instantiating an instance of the struct:
>
>
> directory_list_reu_block_t * constructDirectoryListReuBlock()
> {
> 	directory_list_reu_block_t *result = (directory_list_reu_block_t *)malloc(sizeof(directory_list_reu_block_t));
>
>
>
> 	//log("Constructing Directory List REU Block.");
> 	result->block = 0;
> 	result->next = 0;
> 	result->previous = 0;
> 	memset(result->nodes[0].cbmDirectoryEntry.name, 0, 17);
>
>
> 	memset(result->nodes[1].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[2].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[3].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[4].cbmDirectoryEntry.name, 0, 17);
>
>
> 	memset(result->nodes[5].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[6].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[7].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[8].cbmDirectoryEntry.name, 0, 17);
>
>
> 	memset(result->nodes[9].cbmDirectoryEntry.name, 0, 17);
> 	memset(result->nodes[0].screenCodesName, 32, 17);
> 	memset(result->nodes[1].screenCodesName, 32, 17);
> 	memset(result->nodes[2].screenCodesName, 32, 17);
>
>
> 	memset(result->nodes[3].screenCodesName, 32, 17);
> 	memset(result->nodes[4].screenCodesName, 32, 17);
> 	memset(result->nodes[5].screenCodesName, 32, 17);
> 	memset(result->nodes[6].screenCodesName, 32, 17);
>
>
> 	memset(result->nodes[7].screenCodesName, 32, 17);
> 	memset(result->nodes[8].screenCodesName, 32, 17);
> 	memset(result->nodes[9].screenCodesName, 32, 17);
> 	//log("Constructed Directory List REU Block.");
>
> }
>
>
Found and fixed the problem in the above code.  There is no return
statement in this function, so the return value was random memory locations
 which meant code was getting overwritten.  Is there not supposed to be a
warning or error generated in such a scenario?

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Mar 26 20:32:19 2012

This archive was generated by hypermail 2.1.8 : 2012-03-26 20:32:22 CEST