Potential memory leak on edge cases inside AddFormData() #688

Closed
Dmitry-Me opened this Issue Feb 29, 2016 · 2 comments

Projects

None yet

2 participants

@Dmitry-Me

Cppcheck highlighted this code. lib\formdata.c contains this code with two early returns either of which results in having memory pointed to my newform leaked.

  static CURLcode AddFormData( PARAMS HERE)
 {
     struct FormData *newform = malloc(sizeof(struct FormData));
    if(!newform)
         return CURLE_OUT_OF_MEMORY;
    newform->next = NULL;

   if(length < 0 || (size && *size < 0))
        /* MEMORY LEAK - newform is not freed */
        return CURLE_BAD_FUNCTION_ARGUMENT;

  if(type <= FORM_CONTENT) {
    if(!length)
       /*WHATEVER*/
    else if(length >= (curl_off_t)(size_t)-1)
      /* MEMORY LEAK - newform is not freed */
       return CURLE_BAD_FUNCTION_ARGUMENT;
@bagder bagder added the memory-leak label Feb 29, 2016
@bagder
Member
bagder commented Feb 29, 2016

Yeps, seems like legitimate complaints...

@bagder bagder added a commit that closed this issue Feb 29, 2016
@bagder bagder formpost: fix memory leaks in AddFormData error branches
Reported-by: Dmitry-Me
Fixes #688
c2a809c
@bagder bagder closed this in c2a809c Feb 29, 2016
@bagder
Member
bagder commented Feb 29, 2016

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment