CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: Help! free() invalid pointer error

  1. #16
    Join Date
    Mar 2001
    Posts
    2,527

    Re: Help! free() invalid pointer error

    When you don't post the whole code, you are assuming that you know where the bug is, and that precludes other people from observing all possibilities. Not posting your whole code makes the problem hard to debug by others, and your code frustrating to look at, and well sort of on you to figure out in the end.
    ahoodin
    To keep the plot moving, that's why.

  2. #17
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,149

    Re: Help! free() invalid pointer error

    Code:
    *(message*+size) = '\0';
    assuming this is actual code, then should be
    Code:
    *(*message + size) = '\0';
    but as others have requested, please post actual code.
    Last edited by 2kaud; February 8th, 2016 at 04:10 PM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

  3. #18
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,149

    Re: Help! free() invalid pointer error

    Actually, you don't really need the temp buffer nor explicity null terminate *message. Consider (not tried)
    Code:
    	*message = (uint8_t*)calloc(size + 1, sizeof(uint8_t));
    
    	for (int bytes = 0, ret = 0; bytes < size; bytes += ret)
    		if ((ret = recv(socket, *message + bytes, size - bytes, MSG_NOSIGNAL)) < 0)
    		{
    			free(*message);
    			*message = NULL;
    			return -1;
    		}
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.3)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)