Merge "MediaPlayer: properly handle released surfaces" into ics-mr0
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index f3174fe..63cbf5e 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -274,8 +274,14 @@
     sp<ISurfaceTexture> new_st;
     if (jsurface) {
         sp<Surface> surface(Surface_getSurface(env, jsurface));
-        new_st = surface->getSurfaceTexture();
-        new_st->incStrong(thiz);
+        if (surface != NULL) {
+            new_st = surface->getSurfaceTexture();
+            new_st->incStrong(thiz);
+        } else {
+            jniThrowException(env, "java/lang/IllegalArgumentException",
+                    "The surface has been released");
+            return;
+        }
     }
 
     env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());