Skip to content

Commit

Permalink
Fix curl memory management. (#7760)
Browse files Browse the repository at this point in the history
@mahge
Fix use after free. …
9446e55
  - The variable is used (p->filename is used) after it (p) is freed.

    Free it a little later instead.

@mahge
Free forgotten allocated memory.
13be341

@mahge
Do not clean up before we are done using it. …
aa192a3
  - The result data `msg->data.result` is used to check CURL status.
    If we clean up before we check it we might lose the info in there.
  • Loading branch information
mahge committed Aug 12, 2021
1 parent 4a99720 commit 9604d75
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions OMCompiler/Compiler/runtime/om_curl.c
Expand Up @@ -66,6 +66,7 @@ static void* addTransfer(CURLM *cm, void *urlPathList, int *result)
sprintf(ca_bundle_file, "%s/%s", omhome, CURL_CA_BUNDLE_SUFFIX);
}
curl_easy_setopt(eh, CURLOPT_CAINFO, ca_bundle_file);
free(ca_bundle_file);
}
#endif
curl_easy_setopt(eh, CURLOPT_FOLLOWLOCATION, 1);
Expand Down Expand Up @@ -106,20 +107,22 @@ int om_curl_multi_download(void *urlPathList, int maxParallel)
curl_easy_getinfo(e, CURLINFO_PRIVATE, &p);
FILE *fout = p->fout;
const char *url = p->url;
free(p);

if (msg->msg == CURLMSG_DONE) {
fclose(fout);
curl_multi_remove_handle(cm, e);
curl_easy_cleanup(e);
urlPathList = addTransfer(cm, urlPathList, &result);
if (msg->data.result != CURLE_OK) {
const char *msgs[2] = {curl_easy_strerror(msg->data.result), url};
c_add_message(NULL, -1, ErrorType_runtime,ErrorLevel_error, "Curl error for URL %s: %s", msgs, 2);
omc_unlink(p->filename);
result = 0;
}
} else { /* There should not be any other message types... Ignore it? */
curl_multi_remove_handle(cm, e);
curl_easy_cleanup(e);
}
else { /* There should not be any other message types... Ignore it? */
}
free(p);
}
if (still_alive) {
#if LIBCURL_VERSION_NUM >= 0x071c00 /* curl_multi_wait available since 7.28.0, not on CentOS el6 */
Expand Down

0 comments on commit 9604d75

Please sign in to comment.