Merge branch 'rc/maint-http-local-slot-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Jun 2009 04:15:31 +0000 (21:15 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Jun 2009 04:15:31 +0000 (21:15 -0700)
* rc/maint-http-local-slot-fix:
http*: cleanup slot->local after fclose

1  2 
http-push.c
http-walker.c
diff --combined http-push.c
index e16a0ad3f97ef49930a599d3a800a0c7fad317e0,673a61110e9653a312e3d11bcdb049d181a3898f..0b12ffe18f1197abf1c9351d015fcb0f8ef99931
@@@ -315,9 -315,9 +315,9 @@@ static void start_fetch_loose(struct tr
                 "%s.temp", filename);
  
        snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename);
 -      unlink(prevfile);
 +      unlink_or_warn(prevfile);
        rename(request->tmpfile, prevfile);
 -      unlink(request->tmpfile);
 +      unlink_or_warn(request->tmpfile);
  
        if (request->local_fileno != -1)
                error("fd leakage in start: %d", request->local_fileno);
                } while (prev_read > 0);
                close(prevlocal);
        }
 -      unlink(prevfile);
 +      unlink_or_warn(prevfile);
  
        /* Reset inflate/SHA1 if there was an error reading the previous temp
           file; also rewind to the beginning of the local file. */
@@@ -724,9 -724,11 +724,11 @@@ static void finish_request(struct trans
        struct stat st;
        struct packed_git *target;
        struct packed_git **lst;
+       struct active_request_slot *slot;
  
        request->curl_result = request->slot->curl_result;
        request->http_code = request->slot->http_code;
+       slot = request->slot;
        request->slot = NULL;
  
        /* Keep locks active */
                    request->http_code != 416) {
                        if (stat(request->tmpfile, &st) == 0) {
                                if (st.st_size == 0)
 -                                      unlink(request->tmpfile);
 +                                      unlink_or_warn(request->tmpfile);
                        }
                } else {
                        if (request->http_code == 416)
                        git_inflate_end(&request->stream);
                        git_SHA1_Final(request->real_sha1, &request->c);
                        if (request->zret != Z_STREAM_END) {
 -                              unlink(request->tmpfile);
 +                              unlink_or_warn(request->tmpfile);
                        } else if (hashcmp(request->obj->sha1, request->real_sha1)) {
 -                              unlink(request->tmpfile);
 +                              unlink_or_warn(request->tmpfile);
                        } else {
                                request->rename =
                                        move_temp_to_file(
  
                        fclose(request->local_stream);
                        request->local_stream = NULL;
+                       slot->local = NULL;
                        if (!move_temp_to_file(request->tmpfile,
                                               request->filename)) {
                                target = (struct packed_git *)request->userData;
@@@ -1024,17 -1027,20 +1027,20 @@@ static int fetch_index(unsigned char *s
                if (results.curl_result != CURLE_OK) {
                        free(url);
                        fclose(indexfile);
+                       slot->local = NULL;
                        return error("Unable to get pack index %s\n%s", url,
                                     curl_errorstr);
                }
        } else {
                free(url);
                fclose(indexfile);
+               slot->local = NULL;
                return error("Unable to start request");
        }
  
        free(url);
        fclose(indexfile);
+       slot->local = NULL;
  
        return move_temp_to_file(tmpfile, filename);
  }
@@@ -1415,9 -1421,8 +1421,9 @@@ static void remove_locks(void
  
        fprintf(stderr, "Removing remote locks...\n");
        while (lock) {
 +              struct remote_lock *next = lock->next;
                unlock_remote(lock);
 -              lock = lock->next;
 +              lock = next;
        }
  }
  
diff --combined http-walker.c
index 7321ccc9fe751a1e608c6620bcce401eac7ff98c,ec1c97f2ee04a116e3c1bd22f2f8e2ad2963f5d3..9377851925ae61d60ff6235e8bd8f1c4eeb092b8
@@@ -111,9 -111,9 +111,9 @@@ static void start_object_request(struc
        struct walker_data *data = walker->data;
  
        snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename);
 -      unlink(prevfile);
 +      unlink_or_warn(prevfile);
        rename(obj_req->tmpfile, prevfile);
 -      unlink(obj_req->tmpfile);
 +      unlink_or_warn(obj_req->tmpfile);
  
        if (obj_req->local != -1)
                error("fd leakage in start: %d", obj_req->local);
                } while (prev_read > 0);
                close(prevlocal);
        }
 -      unlink(prevfile);
 +      unlink_or_warn(prevfile);
  
        /* Reset inflate/SHA1 if there was an error reading the previous temp
           file; also rewind to the beginning of the local file. */
@@@ -238,18 -238,18 +238,18 @@@ static void finish_object_request(struc
        } else if (obj_req->curl_result != CURLE_OK) {
                if (stat(obj_req->tmpfile, &st) == 0)
                        if (st.st_size == 0)
 -                              unlink(obj_req->tmpfile);
 +                              unlink_or_warn(obj_req->tmpfile);
                return;
        }
  
        git_inflate_end(&obj_req->stream);
        git_SHA1_Final(obj_req->real_sha1, &obj_req->c);
        if (obj_req->zret != Z_STREAM_END) {
 -              unlink(obj_req->tmpfile);
 +              unlink_or_warn(obj_req->tmpfile);
                return;
        }
        if (hashcmp(obj_req->sha1, obj_req->real_sha1)) {
 -              unlink(obj_req->tmpfile);
 +              unlink_or_warn(obj_req->tmpfile);
                return;
        }
        obj_req->rename =
@@@ -418,15 -418,18 +418,18 @@@ static int fetch_index(struct walker *w
                run_active_slot(slot);
                if (results.curl_result != CURLE_OK) {
                        fclose(indexfile);
+                       slot->local = NULL;
                        return error("Unable to get pack index %s\n%s", url,
                                     curl_errorstr);
                }
        } else {
                fclose(indexfile);
+               slot->local = NULL;
                return error("Unable to start request");
        }
  
        fclose(indexfile);
+       slot->local = NULL;
  
        return move_temp_to_file(tmpfile, filename);
  }
@@@ -776,16 -779,19 +779,19 @@@ static int fetch_pack(struct walker *wa
                run_active_slot(slot);
                if (results.curl_result != CURLE_OK) {
                        fclose(packfile);
+                       slot->local = NULL;
                        return error("Unable to get pack file %s\n%s", url,
                                     curl_errorstr);
                }
        } else {
                fclose(packfile);
+               slot->local = NULL;
                return error("Unable to start request");
        }
  
        target->pack_size = ftell(packfile);
        fclose(packfile);
+       slot->local = NULL;
  
        ret = move_temp_to_file(tmpfile, filename);
        if (ret)
@@@ -809,7 -815,7 +815,7 @@@ static void abort_object_request(struc
                close(obj_req->local);
                obj_req->local = -1;
        }
 -      unlink(obj_req->tmpfile);
 +      unlink_or_warn(obj_req->tmpfile);
        if (obj_req->slot) {
                release_active_slot(obj_req->slot);
                obj_req->slot = NULL;