egl: cleanup code and fix memory leaks in