zinx icon indicating copy to clipboard operation
zinx copied to clipboard

timerscheduler的CancelTimer,ids有可能越界

Open zhangxa opened this issue 5 years ago • 3 comments

//删除timer func (this *TimerScheduler) CancelTimer(tid uint32) { this.Lock() this.Unlock() //this.tw.RemoveTimer(tid) 这个方法无效 //删除timerId var index = -1 //此处的0可修改为-1 for i := 0; i < len(this.ids); i++ { if this.ids[i] == tid { index = i } } //此处加个判断 if index > -1 { this.ids = append(this.ids[:index], this.ids[index+1:]...) }

}

zhangxa avatar Nov 27 '20 06:11 zhangxa

感谢提供PR,已经修正。https://github.com/aceld/zinx/blob/master/ztimer/timerscheduler.go

//删除timer
func (this *TimerScheduler) CancelTimer(tid uint32) {
	this.Lock()
	this.Unlock()
	//this.tw.RemoveTimer(tid)  这个方法无效
	//删除timerId
	var index = -1
	for i := 0; i < len(this.ids); i++ {
		if this.ids[i] == tid {
			index = i
		}
	}

	if index > -1 {
		this.ids = append(this.ids[:index], this.ids[index+1:]...)
	}
}

aceld avatar Dec 01 '20 06:12 aceld

this.Unlock() //此处是不是少了 defer ?

//删除timer
func (this *TimerScheduler) CancelTimer(tid uint32) {
	this.Lock()
	this.Unlock()   //此处是不是少了 defer  ?
	//this.tw.RemoveTimer(tid)  这个方法无效
	//删除timerId
	var index = -1
	for i := 0; i < len(this.ids); i++ {
		if this.ids[i] == tid {
			index = i
		}
	}

	if index > -1 {
		this.ids = append(this.ids[:index], this.ids[index+1:]...)
	}
}

me10001 avatar Jan 20 '21 01:01 me10001

@me10001 @aceld 确实是少了defer

zhangxa avatar Jan 21 '21 07:01 zhangxa

已更正。

aceld avatar Apr 06 '23 01:04 aceld