Commit affed672 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

smtp_mail: fix memory leak

... introduced in 7f304ab8
parent 7f304ab8
Loading
Loading
Loading
Loading
+13 −3
Original line number Original line Diff line number Diff line
@@ -795,16 +795,23 @@ static CURLcode smtp_mail(struct connectdata *conn)
  /* calculate the FROM parameter */
  /* calculate the FROM parameter */
  if(!data->set.str[STRING_MAIL_FROM])
  if(!data->set.str[STRING_MAIL_FROM])
    /* null reverse-path, RFC-2821, sect. 3.7 */
    /* null reverse-path, RFC-2821, sect. 3.7 */
    from = "<>";
    from = strdup("<>");
  else if(data->set.str[STRING_MAIL_FROM][0] == '<')
  else if(data->set.str[STRING_MAIL_FROM][0] == '<')
    from = aprintf("%s", data->set.str[STRING_MAIL_FROM]);
    from = aprintf("%s", data->set.str[STRING_MAIL_FROM]);
  else
  else
    from = aprintf("<%s>", data->set.str[STRING_MAIL_FROM]);
    from = aprintf("<%s>", data->set.str[STRING_MAIL_FROM]);


  if(!from)
    return CURLE_OUT_OF_MEMORY;

  /* calculate the optional SIZE parameter */
  /* calculate the optional SIZE parameter */
  if(conn->data->set.infilesize > 0)
  if(conn->data->set.infilesize > 0) {
    size = aprintf("%" FORMAT_OFF_T, data->set.infilesize);
    size = aprintf("%" FORMAT_OFF_T, data->set.infilesize);


    if(!size)
      return CURLE_OUT_OF_MEMORY;
  }

  /* send MAIL FROM */
  /* send MAIL FROM */
  if(size == NULL)
  if(size == NULL)
    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s", from);
    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s", from);
@@ -812,6 +819,9 @@ static CURLcode smtp_mail(struct connectdata *conn)
    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s SIZE=%s",
    result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s SIZE=%s",
                           from, size);
                           from, size);


  Curl_safefree(size);
  Curl_safefree(from);

  if(result)
  if(result)
    return result;
    return result;