Commits

w...@styx.org  committed d2b7f2f

do not overuse defer

  • Participants
  • Parent commits 72d1703

Comments (0)

Files changed (1)

 	out = make(chan []byte)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			k, err := cur.GetKey(true)
 			if err != nil {
 			}
 			out <- k
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 	out = make(chan []byte)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			v, err := cur.GetValue(true)
 			if err != nil {
 			}
 			out <- v
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 	out = make(chan *Item)
 	go func() {
 		cur := kc.Cursor()
-		defer func() {
-			cur.Del()
-			close(out)
-		}()
 		for {
 			k, v, err := cur.Get(true)
 			if err != nil {
 			}
 			out <- &Item{k, v}
 		}
+		cur.Del()
+		close(out)
 	}()
 	return
 }
 
 func (kc *KCDB) MatchPrefix(prefix string, max int) (matches [][]byte, err os.Error) {
 	cprefix := C.CString(prefix)
-	defer C.free(unsafe.Pointer(cprefix))
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchprefix(kc.db, cprefix, &strarray[0], C.size_t(max))
 	if count == -1 {
 			C.kcfree(unsafe.Pointer(strarray[i]))
 		}
 	}
+	C.free(unsafe.Pointer(cprefix))
 	return
 }
 
 func (kc *KCDB) MatchRegex(regex string, max int) (matches [][]byte, err os.Error) {
 	cregex := C.CString(regex)
-	defer C.free(unsafe.Pointer(cregex))
 	strarray := make([]*C.char, max)
 	count := C.kcdbmatchregex(kc.db, cregex, &strarray[0], C.size_t(max))
 	if count == -1 {
 			C.kcfree(unsafe.Pointer(strarray[i]))
 		}
 	}
+	C.free(unsafe.Pointer(cregex))
 	return
 }