Skip to content

Potential memory leak in getinmemory.c example #2991

Closed

Description

@CrazyHackGUT

mem->memory = realloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}

realloc can return null if he can't extend the memory. This case here envisaged, but...
realloc doesn't clean memory. We got a memory leak if realloc return null.

If we open realloc documentation, we can see:

A null-pointer indicates that the function failed to allocate storage, and thus the block pointed by ptr was not modified.

Activity

  1. danielgustafsson commented on Sep 14, 2018

    @danielgustafsson
    Contributor
  2. danielgustafsson commented on Sep 14, 2018

    @danielgustafsson
    Contributor
  3. CrazyHackGUT commented on Sep 14, 2018

    @CrazyHackGUT
    ContributorAuthor

    Ok, I create PR later.

  4. danielgustafsson commented on Sep 14, 2018

    @danielgustafsson
    Contributor
  5. added a commit that references this issue on Sep 15, 2018
  6. CrazyHackGUT commented on Sep 15, 2018

    @CrazyHackGUT
    ContributorAuthor

    I missed one time and created pull also in my fork 🤣
    Just ignore him in this issue.

  7. bagder commented on Sep 18, 2018

    @bagder
    Member

    Fixed in 23524bf

  8. locked as resolved and limited conversation to collaborators on Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions