This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

realloc bug in HeapMem?

Other Parts Discussed in Thread: SYSBIOS, CC3200

Hello,

we make use of realloc with a pointer to pointer and the result is this assertion:

ti.sysbios.heaps.HeapMem: line 348: assertion failure: A_invalidFree: Invalid free
xdc.runtime.Error.raise: terminating execution

We tested our code on a x86 platform to verify the correct use of the pointers and the code runs fine. 

Either the realloc implementation in SYSBIOS is faulty, either the memory allocation in CC3200 presents some issue that we may not be aware of.

The code to test:

*readBuffer = malloc(500 * sizeof(unsigned char));

[...]


HTTPCli_getResponseField(httpClient, (char *)*readBuffer, 500, &moreFlags)


[...]
len = strtoul((char *)*readBuffer, NULL, 0); *readBuffer = realloc(*readBuffer, (len + 1) * sizeof(unsigned char));

readBuffer is a valid string and  contains data got from HTTP, we can read it with debugger, do strcmp and other operations without issues. 

In other parts of the application we use realloc with pointers (and not pointers to pointers such as here) and it works fine.

  • Leonardo,

    I just gave it a quick try. It works as expected.

    Here is a code snippet that I ran inside a task:

    	void *p = NULL;
    	void **readBuffer = &p;
    
    	*readBuffer = malloc(512 * sizeof(unsigned char));
    	if (*readBuffer) {
    		System_printf("malloc succeeded!\n");
    	}
    	else {
    		System_printf("malloc failed!\n");
    	}
    
    	*readBuffer = realloc(*readBuffer, 1024 * sizeof(unsigned char));
    	if (*readBuffer) {
    		System_printf("remalloc succeeded!\n");
    	}
    	else {
    		System_printf("remalloc failed!\n");
    	}
    
    	System_flush();
    
    	free(*readBuffer);

    It printed the success messages as expected. I couldn't see the "readBuffer" declaration in your code snippet. Check and make sure it's not NULL.

    Vikram