cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl segfaults on file transfer

From: Ryan <rcdetert_at_ucdavis.edu>
Date: Mon, 16 Aug 2004 00:31:15 -0700

This is a follow-up to an earlier question about deleting files.
I have been having a hard time transferring files in libcurl. I have
found that adding a file to a form and transmitting it is causing all of
my problems and I'm not sure why.

I am iterating through every file in a directory, curling the file via
formadd() and then deleting the file. I can delete all the files just
fine (if I don't curl), or I can curl just fine (if I don't delete) but
not both.

Here is the code I'm using is pasted at the end of the email. The line
that is commented out is the one giving me problems. I tried using
curl_formfree() as well but that gave me segfault right away. With the
curl_formadd(...CURLFORM_FILE....) I get sporadic results which end in a
segfault after having read a couple of files.

I'm on linux using fedora core 2 on gcc 3.3.3.

does anyone know why the file upload is giving problems when I try to
delete?

----------------------------------------------
        hCURL = curl_easy_init();
                
        d = opendir(logdir);
        while ( (pdirent = readdir(d)) != NULL ){
                if(!strcmp(pdirent->d_name, ".") || !strcmp(pdirent->d_name, ".."))
continue;
                if(!strcmp(filename, pdirent->d_name)) continue;

                strcpy(relPath, logdir);
                strcat(relPath, pdirent->d_name);
#if 1
                curl_easy_setopt(hCURL, CURLOPT_URL, "http://stuff/test.php");
                curl_formadd(&post, &last, CURLFORM_COPYNAME, "user",
CURLFORM_COPYCONTENTS, login, CURLFORM_END);
                curl_formadd(&post, &last, CURLFORM_COPYNAME, "pass",
CURLFORM_COPYCONTENTS, pword, CURLFORM_END);
                //curl_formadd(&post, &last, CURLFORM_COPYNAME, "tracefile",
CURLFORM_FILE, relPath, CURLFORM_END);
                curl_easy_setopt(hCURL, CURLOPT_HTTPPOST, post);
                retVal = curl_easy_perform(hCURL);
#endif
                newPath[2] = '\0';
                strcat(newPath, relPath);
        
                if( retVal == 0 )
                        unlink(newPath);
        }
        curl_easy_cleanup(hCURL);

-------------------------------------------------
Received on 2004-08-16