Skip to content

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

@Dmitry-Me

Description

@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;

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