-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Closed
Labels
Description
HI, in this function, it is possible that the lock lock (Line 71) is not released properly because the execution does not enter the while(j < num_urls)? Also, it also seems that the lock lock could be released multiple times in the while loop at Line 97.
Thanks for checking.
curl/docs/examples/smooth-gtk-thread.c
Lines 68 to 113 in 3085ccf
| void *pull_one_url(void *NaN) | |
| { | |
| /* Stop threads from entering unless j is incremented */ | |
| pthread_mutex_lock(&lock); | |
| while(j < num_urls) { | |
| CURL *curl; | |
| gchar *http; | |
| printf("j = %d\n", j); | |
| http = | |
| g_strdup_printf("xoap.weather.com/weather/local/%s?cc=*&dayf=5&unit=i\n", | |
| urls[j]); | |
| printf("http %s", http); | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| FILE *outfile = fopen(urls[j], "wb"); | |
| /* Set the URL and transfer type */ | |
| curl_easy_setopt(curl, CURLOPT_URL, http); | |
| /* Write to the file */ | |
| curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); | |
| curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_file); | |
| j++; /* critical line */ | |
| pthread_mutex_unlock(&lock); | |
| curl_easy_perform(curl); | |
| fclose(outfile); | |
| printf("fclose\n"); | |
| curl_easy_cleanup(curl); | |
| } | |
| g_free(http); | |
| /* Adds more latency, testing the mutex.*/ | |
| sleep(1); | |
| } /* end while */ | |
| return NULL; | |
| } |