Progress on upload
[citadel.git] / webcit-ng / server / upload.c
index 101d7894882493363773602817a3ce1dcc5e8a91..356cd1d750493c087cc98ef1968e26be91a212e3 100644 (file)
@@ -40,12 +40,17 @@ void upload_handler(char *name, char *filename, char *partnum, char *disp,
        u.length = length;
 
        // Write the upload to a file that we can access later when the user saves the message.
+       // tmpfile() creates a file with zero links in the directory, so it will be deleted when it is closed.
        u.fp = tmpfile();
        if (!u.fp) {
                syslog(LOG_ERR, "upload: %m");
                return;
        }
-       fwrite(content, length, 1, u.fp);                       // this file will be deleted by the OS when it is closed
+       if (fwrite(content, length, 1, u.fp) != 1) {
+               syslog(LOG_ERR, "upload: %m");
+               fclose(u.fp);
+               return;
+       }
 
        // Add it to the list of uploads the server is holding.
        pthread_mutex_lock(&upload_list_mutex);