 		checkCudaErrors(cudaFree(d_kgy));
 
 		//free cpu memory. 
-		free(k_gx);
-		free(k_gy);
-
-	}
-}
-
+		delete[] k_gx;
+		delete[] k_gy;
+
+	}
+}
+

			checkCudaErrors(cudaFree(d_out));
			checkCudaErrors(cudaFree(d_filter));

			free(h_filter);
			break;
		}
		

		//check the image type.
		gimage::Type t = input.getType();
		switch (t) {
		case TYPE_UINT16:
			gimage::MatrixU16 blurred(input.size());
			//run gaussian blur first. 
			gaussianBlur(input, blurred, sigma, numRows, numCols, 5);
			uint16_t *d_gradient;
			uint16_t *d_in;
			int *d_theta;
			//allocate all our arrays. 
			checkCudaErrors(cudaMalloc(&d_gradient, input.totalSize()));
			checkCudaErrors(cudaMalloc(&d_theta, sizeof(int)*numRows*numCols));
			checkCudaErrors(cudaMalloc(&d_in, input.totalSize()));
