src/mime.c
branch2028_fix
changeset 2035 61b05d325adc
parent 2028 fa5a0fb170ba
child 2036 81c4285cd4fc
     1.1 --- a/src/mime.c	Tue Sep 05 18:46:05 2017 +0200
     1.2 +++ b/src/mime.c	Wed Sep 06 01:48:08 2017 +0200
     1.3 @@ -696,13 +696,17 @@
     1.4      assert(msg);
     1.5      assert(result);
     1.6  
     1.7 -    message* duped_msg = message_dup(msg);
     1.8 +    bloblist_t* inlined_attachments = NULL;
     1.9 +    bloblist_t* normal_attachments = NULL;
    1.10  
    1.11 -    if (!duped_msg) {
    1.12 -        status = PEP_OUT_OF_MEMORY;
    1.13 -        goto pep_error;
    1.14 +    if (msg->attachments) {
    1.15 +        normal_attachments = bloblist_dup(msg->attachments);
    1.16 +        if (!normal_attachments) {
    1.17 +            status = PEP_OUT_OF_MEMORY;
    1.18 +            goto pep_error;
    1.19 +        }
    1.20      }
    1.21 -
    1.22 +    
    1.23      //subject = (msg->shortmsg) ? msg->shortmsg : "pEp";  // not used, yet.
    1.24      plaintext = (msg->longmsg) ? msg->longmsg : "";
    1.25      htmltext = msg->longmsg_formatted;
    1.26 @@ -711,10 +715,8 @@
    1.27          /* first, we need to strip out the inlined attachments to ensure this
    1.28             gets set up correctly */
    1.29          
    1.30 -        bloblist_t* inlined_attachments = NULL;
    1.31 -        /* Noooooo... dirk, why do you do this to me? */
    1.32 -                
    1.33 -        split_inlined_and_attached(&inlined_attachments, &duped_msg->attachments);
    1.34 +        /* Noooooo... dirk, why do you do this to me? */                
    1.35 +        split_inlined_and_attached(&inlined_attachments, &normal_attachments);
    1.36  
    1.37          status = mime_html_text(plaintext, htmltext, inlined_attachments, &mime);
    1.38                  
    1.39 @@ -740,7 +742,7 @@
    1.40              goto enomem;
    1.41      }
    1.42  
    1.43 -    if (duped_msg->attachments) {
    1.44 +    if (normal_attachments) {
    1.45          submime = mime;
    1.46          mime = part_multiple_new("multipart/mixed");
    1.47          assert(mime);
    1.48 @@ -758,8 +760,13 @@
    1.49          }
    1.50  
    1.51          bloblist_t *_a;
    1.52 -        for (_a = duped_msg->attachments; _a != NULL; _a = _a->next) {
    1.53 +        for (_a = normal_attachments; _a != NULL; _a = _a->next) {
    1.54  
    1.55 +            // FIXME: As far as I can tell, mime_attachment takes ownership of
    1.56 +            // _a->value, so the shell of this bloblist_t is now lost memory.
    1.57 +            // not a problem if we can free the whole message later, but
    1.58 +            // this solution is bad. Need to make a more fundamental message
    1.59 +            // change somewhere, I guess.
    1.60              status = mime_attachment(_a, &submime);
    1.61              if (status != PEP_STATUS_OK)
    1.62                  goto pep_error;
    1.63 @@ -776,10 +783,6 @@
    1.64          }
    1.65      }
    1.66  
    1.67 -
    1.68 -
    1.69 -    if (duped_msg)
    1.70 -        free_message(duped_msg);
    1.71      *result = mime;
    1.72      return PEP_STATUS_OK;
    1.73  
    1.74 @@ -793,8 +796,11 @@
    1.75      if (submime)
    1.76          mailmime_free(submime);
    1.77  
    1.78 -    if (duped_msg)
    1.79 -        free_message(duped_msg);
    1.80 +    if (inlined_attachments)
    1.81 +        free_bloblist(inlined_attachments);
    1.82 +
    1.83 +    if (normal_attachments)
    1.84 +        free_bloblist(normal_attachments);
    1.85  
    1.86      return status;
    1.87  }