Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Possible memory leak: Tensor.Close returns early on the CUDA path and skips two frees

Aperta Adatta ai principianti
#2,558 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
84/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
c, go
Ambito
performance

Direzione di ricerca

Leggi go/dlpack.go intorno alla riga 184 e traccia Tensor.Close insieme alle allocazioni in NewTensorOnDevice. Verifica che il percorso CUDA continui a rilasciare il shape array e DLManagedTensor dopo la pulizia del dispositivo, quindi esegui i percorsi di creazione dell'indice e di ricerca per confermare che i tensori GPU non conservino più quelle allocazioni sull'host.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Possible memory leak: Tensor.Close returns early on the CUDA path and skips two frees

Close handles the device data in the kDLCUDA branch and returns from inside
it, so the shared cleanup below the branch never runs for GPU tensors.

go/dlpack.go:184

func (t *Tensor[T]) Close() error {
	if t.C_tensor.dl_tensor.device.device_type == C.kDLCUDA {
		bytes := t.sizeInBytes()
		res, err := NewResource(nil)
		if err != nil {
			return err
		}
		err = CheckCuvs(CuvsError(C.cuvsRMMFree(res.Resource, t.C_tensor.dl_tensor.data, C.size_t(bytes))))

		return err
	} else if t.C_tensor.dl_tensor.device.device_type == C.kDLCPU {
		if t.C_tensor.dl_tensor.data != nil {
			C.free(t.C_tensor.dl_tensor.data)
			t.C_tensor.dl_tensor.data = nil
		}
	}

	if t.C_tensor.dl_tensor.shape != nil {
		C.free(unsafe.Pointer(t.C_tensor.dl_tensor.shape))
		t.C_tensor.dl_tensor.shape = nil
	}

	if t.C_tensor != nil {
		C.free(unsafe.Pointer(t.C_tensor))
		t.C_tensor = nil
	}

Both skipped frees release host memory that NewTensorOnDevice allocated with
C.malloc:

	shapePtr := C.malloc(C.size_t(len(shape) * int(unsafe.Sizeof(C.int64_t(0)))))
	...
	dlm := (*C.DLManagedTensor)(C.malloc(C.size_t(unsafe.Sizeof(C.DLManagedTensor{}))))

The CPU branch falls through and frees all three, which is what makes the CUDA
path stand out. Every GPU tensor therefore leaks len(shape)*8 bytes for the
shape array plus one DLManagedTensor on the host, and these are created per
index build and per search.

Fix: replace the return err in the CUDA branch with an assignment to a named
error, and let control fall through to the shape and tensor frees.

If you could credit me as a reporter for my contributions to security advisory I will be thankful.

Lingua principale
Cuda
Stelle
869
Fork
243
Merge medio
3g 15h
PR unite (30g)
78

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NVIDIA/cuvs

Tutte le issue di NVIDIA/cuvs

Issue simili

Altre issue su Performance

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.