mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 11:28:24 +00:00 
			
		
		
		
	There are multiple places where wiki git repositories are not properly closed. This PR ensures they are closed. Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		| @@ -131,6 +131,9 @@ func wikiContentsByName(ctx *context.Context, commit *git.Commit, wikiName strin | |||||||
| func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { | func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { | ||||||
| 	wikiRepo, commit, err := findWikiRepoCommit(ctx) | 	wikiRepo, commit, err := findWikiRepoCommit(ctx) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		if wikiRepo != nil { | ||||||
|  | 			wikiRepo.Close() | ||||||
|  | 		} | ||||||
| 		if !git.IsErrNotExist(err) { | 		if !git.IsErrNotExist(err) { | ||||||
| 			ctx.ServerError("GetBranchCommit", err) | 			ctx.ServerError("GetBranchCommit", err) | ||||||
| 		} | 		} | ||||||
| @@ -354,17 +357,14 @@ func Wiki(ctx *context.Context) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	wikiRepo, entry := renderViewPage(ctx) | 	wikiRepo, entry := renderViewPage(ctx) | ||||||
| 	if ctx.Written() { |  | ||||||
| 		if wikiRepo != nil { |  | ||||||
| 			wikiRepo.Close() |  | ||||||
| 		} |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if wikiRepo != nil { | 		if wikiRepo != nil { | ||||||
| 			wikiRepo.Close() | 			wikiRepo.Close() | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|  | 	if ctx.Written() { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	if entry == nil { | 	if entry == nil { | ||||||
| 		ctx.Data["Title"] = ctx.Tr("repo.wiki") | 		ctx.Data["Title"] = ctx.Tr("repo.wiki") | ||||||
| 		ctx.HTML(200, tplWikiStart) | 		ctx.HTML(200, tplWikiStart) | ||||||
| @@ -399,17 +399,15 @@ func WikiRevision(ctx *context.Context) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	wikiRepo, entry := renderRevisionPage(ctx) | 	wikiRepo, entry := renderRevisionPage(ctx) | ||||||
| 	if ctx.Written() { |  | ||||||
| 		if wikiRepo != nil { |  | ||||||
| 			wikiRepo.Close() |  | ||||||
| 		} |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		if wikiRepo != nil { | 		if wikiRepo != nil { | ||||||
| 			wikiRepo.Close() | 			wikiRepo.Close() | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
|  | 	if ctx.Written() { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	if entry == nil { | 	if entry == nil { | ||||||
| 		ctx.Data["Title"] = ctx.Tr("repo.wiki") | 		ctx.Data["Title"] = ctx.Tr("repo.wiki") | ||||||
| 		ctx.HTML(200, tplWikiStart) | 		ctx.HTML(200, tplWikiStart) | ||||||
| @@ -446,13 +444,14 @@ func WikiPages(ctx *context.Context) { | |||||||
| 		} | 		} | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 	defer func() { | ||||||
| 	entries, err := commit.ListEntries() |  | ||||||
| 	if err != nil { |  | ||||||
| 		if wikiRepo != nil { | 		if wikiRepo != nil { | ||||||
| 			wikiRepo.Close() | 			wikiRepo.Close() | ||||||
| 		} | 		} | ||||||
|  | 	}() | ||||||
|  |  | ||||||
|  | 	entries, err := commit.ListEntries() | ||||||
|  | 	if err != nil { | ||||||
| 		ctx.ServerError("ListEntries", err) | 		ctx.ServerError("ListEntries", err) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @@ -463,10 +462,6 @@ func WikiPages(ctx *context.Context) { | |||||||
| 		} | 		} | ||||||
| 		c, err := wikiRepo.GetCommitByPath(entry.Name()) | 		c, err := wikiRepo.GetCommitByPath(entry.Name()) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			if wikiRepo != nil { |  | ||||||
| 				wikiRepo.Close() |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			ctx.ServerError("GetCommit", err) | 			ctx.ServerError("GetCommit", err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| @@ -475,10 +470,6 @@ func WikiPages(ctx *context.Context) { | |||||||
| 			if models.IsErrWikiInvalidFileName(err) { | 			if models.IsErrWikiInvalidFileName(err) { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 			if wikiRepo != nil { |  | ||||||
| 				wikiRepo.Close() |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			ctx.ServerError("WikiFilenameToName", err) | 			ctx.ServerError("WikiFilenameToName", err) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| @@ -490,21 +481,25 @@ func WikiPages(ctx *context.Context) { | |||||||
| 	} | 	} | ||||||
| 	ctx.Data["Pages"] = pages | 	ctx.Data["Pages"] = pages | ||||||
|  |  | ||||||
| 	defer func() { |  | ||||||
| 		if wikiRepo != nil { |  | ||||||
| 			wikiRepo.Close() |  | ||||||
| 		} |  | ||||||
| 	}() |  | ||||||
| 	ctx.HTML(200, tplWikiPages) | 	ctx.HTML(200, tplWikiPages) | ||||||
| } | } | ||||||
|  |  | ||||||
| // WikiRaw outputs raw blob requested by user (image for example) | // WikiRaw outputs raw blob requested by user (image for example) | ||||||
| func WikiRaw(ctx *context.Context) { | func WikiRaw(ctx *context.Context) { | ||||||
| 	wikiRepo, commit, err := findWikiRepoCommit(ctx) | 	wikiRepo, commit, err := findWikiRepoCommit(ctx) | ||||||
| 	if err != nil { | 	defer func() { | ||||||
| 		if wikiRepo != nil { | 		if wikiRepo != nil { | ||||||
|  | 			wikiRepo.Close() | ||||||
|  | 		} | ||||||
|  | 	}() | ||||||
|  |  | ||||||
|  | 	if err != nil { | ||||||
|  | 		if git.IsErrNotExist(err) { | ||||||
|  | 			ctx.NotFound("findEntryForFile", nil) | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  | 		ctx.ServerError("findEntryForfile", err) | ||||||
|  | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	providedPath := ctx.Params("*") | 	providedPath := ctx.Params("*") | ||||||
| @@ -520,9 +515,7 @@ func WikiRaw(ctx *context.Context) { | |||||||
|  |  | ||||||
| 		if entry == nil { | 		if entry == nil { | ||||||
| 			// Try to find a wiki page with that name | 			// Try to find a wiki page with that name | ||||||
| 			if strings.HasSuffix(providedPath, ".md") { | 			providedPath = strings.TrimSuffix(providedPath, ".md") | ||||||
| 				providedPath = providedPath[:len(providedPath)-3] |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			wikiPath := wiki_service.NameToFilename(providedPath) | 			wikiPath := wiki_service.NameToFilename(providedPath) | ||||||
| 			entry, err = findEntryForFile(commit, wikiPath) | 			entry, err = findEntryForFile(commit, wikiPath) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user