Skip to content

Commit d2288ec

Browse files
committed
Clarify memory usage and slightly improve sapi_read_post_data
This is a result of checking GH-8800 which assumed potential memory leaks here. Even though it was not the case in reality, the function deserves a bit of clarification to prevent similar attempts in the future.
1 parent 5b1ba48 commit d2288ec

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

main/SAPI.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void sapi_read_post_data(void)
183183
* - Make the content type lowercase
184184
* - Trim descriptive data, stay with the content-type only
185185
*/
186-
for (p=content_type; p<content_type+content_type_length; p++) {
186+
for (p = content_type; p < content_type + content_type_length; p++) {
187187
switch (*p) {
188188
case ';':
189189
case ',':
@@ -207,17 +207,19 @@ static void sapi_read_post_data(void)
207207
} else {
208208
/* fallback */
209209
SG(request_info).post_entry = NULL;
210-
if (!sapi_module.default_post_reader) {
211-
/* no default reader? */
210+
if (UNEXPECTED(!sapi_module.default_post_reader)) {
211+
/* this should not happen as there should always be a default_post_reader */
212212
SG(request_info).content_type_dup = NULL;
213213
sapi_module.sapi_error(E_WARNING, "Unsupported content type: '%s'", content_type);
214+
efree(content_type);
214215
return;
215216
}
216217
}
217218
if (oldchar) {
218219
*(p-1) = oldchar;
219220
}
220221

222+
/* the content_type_dup is not set at this stage so no need to try to free it first */
221223
SG(request_info).content_type_dup = content_type;
222224

223225
if(post_reader_func) {

0 commit comments

Comments
 (0)