 					best_idx = 0;
 					best_dist = FLT_MAX;
 				}
+				//free(temp_index);
+				//free(temp_dists);
 				break;
 			}
 			else if (query.coords[split_axis] < nodes[cur].split_value){

					neighbor_nb = nodes[cur].num_indexes;
				}
				*ret_node = cur;

				//Now we get enough neighbors in cur node
				int *temp_index = (int*)malloc(sizeof(int) * nodes[cur].num_indexes);
				double *temp_dists = (double*)malloc(sizeof(double) * nodes[cur].num_indexes);

				for (int i = 0; i < nodes[cur].num_indexes; ++i)
				{
					temp_index[i] = indexes[nodes[cur].indexes + i];
					temp_dists[i] = Distance(query, pts[temp_index[i]]);
				}

				int n = nodes[cur].num_indexes;
				//kðݵõǰСľ
				int best_idx = 0;


			if (nodes[cur].left == -1){
				//Get to the leaf node
				
				neighbor_nb += nodes[cur].num_indexes;
				while (neighbor_nb < k)
				{
