comparison mail.c @ 9:8966edef462a

Add more uw_strdup, which seems to avoid problems from reuse of memory
author Adam Chlipala <adam@chlipala.net>
date Thu, 04 Feb 2016 17:50:25 -0500
parents fe6049d23ce5
children
comparison
equal deleted inserted replaced
8:fe6049d23ce5 9:8966edef462a
59 } 59 }
60 60
61 ok: 61 ok:
62 */ 62 */
63 address(ctx, s); 63 address(ctx, s);
64 h2->from = s; 64 h2->from = uw_strdup(ctx, s);
65 65
66 return h2; 66 return h2;
67 } 67 }
68 68
69 uw_Mail_headers uw_Mail_to(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) { 69 uw_Mail_headers uw_Mail_to(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) {
77 if (h2->to) { 77 if (h2->to) {
78 uw_Basis_string all = uw_malloc(ctx, strlen(h2->to) + 2 + strlen(s)); 78 uw_Basis_string all = uw_malloc(ctx, strlen(h2->to) + 2 + strlen(s));
79 sprintf(all, "%s,%s", h2->to, s); 79 sprintf(all, "%s,%s", h2->to, s);
80 h2->to = all; 80 h2->to = all;
81 } else 81 } else
82 h2->to = s; 82 h2->to = uw_strdup(ctx, s);
83
84 fprintf(stderr, "TO: %s\n", h2->to);
83 85
84 return h2; 86 return h2;
85 } 87 }
86 88
87 uw_Mail_headers uw_Mail_cc(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) { 89 uw_Mail_headers uw_Mail_cc(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) {
95 if (h2->cc) { 97 if (h2->cc) {
96 uw_Basis_string all = uw_malloc(ctx, strlen(h2->cc) + 2 + strlen(s)); 98 uw_Basis_string all = uw_malloc(ctx, strlen(h2->cc) + 2 + strlen(s));
97 sprintf(all, "%s,%s", h2->cc, s); 99 sprintf(all, "%s,%s", h2->cc, s);
98 h2->cc = all; 100 h2->cc = all;
99 } else 101 } else
100 h2->cc = s; 102 h2->cc = uw_strdup(ctx, s);
101 103
102 return h2; 104 return h2;
103 } 105 }
104 106
105 uw_Mail_headers uw_Mail_bcc(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) { 107 uw_Mail_headers uw_Mail_bcc(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) {
113 if (h2->bcc) { 115 if (h2->bcc) {
114 uw_Basis_string all = uw_malloc(ctx, strlen(h2->bcc) + 2 + strlen(s)); 116 uw_Basis_string all = uw_malloc(ctx, strlen(h2->bcc) + 2 + strlen(s));
115 sprintf(all, "%s,%s", h2->bcc, s); 117 sprintf(all, "%s,%s", h2->bcc, s);
116 h2->bcc = all; 118 h2->bcc = all;
117 } else 119 } else
118 h2->bcc = s; 120 h2->bcc = uw_strdup(ctx, s);
119 121
120 return h2; 122 return h2;
121 } 123 }
122 124
123 uw_Mail_headers uw_Mail_subject(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) { 125 uw_Mail_headers uw_Mail_subject(uw_context ctx, uw_Basis_string s, uw_Mail_headers h) {
130 132
131 if (h2->subject) 133 if (h2->subject)
132 uw_error(ctx, FATAL, "Duplicate Subject header"); 134 uw_error(ctx, FATAL, "Duplicate Subject header");
133 135
134 header(ctx, s); 136 header(ctx, s);
135 h2->subject = s; 137 h2->subject = uw_strdup(ctx, s);
136 138
137 return h2; 139 return h2;
138 } 140 }
139 141
140 typedef struct { 142 typedef struct {