@@ -1085,8 +1085,7 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
10851085 } else if (raw_std_value_is_string (arg )) {
10861086 asset = raw_std_string_dup (arg );
10871087 if (asset == NULL ) {
1088- ok = ENOMEM ;
1089- goto fail_respond_error ;
1088+ return platch_respond_native_error_std (responsehandle , ENOMEM );
10901089 }
10911090 } else {
10921091 return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[0]` to be a String or null." );
@@ -1104,11 +1103,12 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
11041103 } else if (raw_std_value_is_string (arg )) {
11051104 package_name = raw_std_string_dup (arg );
11061105 if (package_name == NULL ) {
1107- ok = ENOMEM ;
1108- goto fail_respond_error ;
1106+ ok = platch_respond_native_error_std ( responsehandle , ENOMEM ) ;
1107+ goto fail_free_asset ;
11091108 }
11101109 } else {
1111- return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[1]` to be a String or null." );
1110+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected `arg[1]` to be a String or null." );
1111+ goto fail_free_asset ;
11121112 }
11131113 } else {
11141114 package_name = NULL ;
@@ -1123,11 +1123,12 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
11231123 } else if (raw_std_value_is_string (arg )) {
11241124 uri = raw_std_string_dup (arg );
11251125 if (uri == NULL ) {
1126- ok = ENOMEM ;
1127- goto fail_respond_error ;
1126+ ok = platch_respond_native_error_std ( responsehandle , ENOMEM ) ;
1127+ goto fail_free_package_name ;
11281128 }
11291129 } else {
1130- return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[2]` to be a String or null." );
1130+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected `arg[2]` to be a String or null." );
1131+ goto fail_free_package_name ;
11311132 }
11321133 } else {
11331134 uri = NULL ;
@@ -1153,7 +1154,8 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
11531154 }
11541155 } else {
11551156invalid_format_hint :
1156- return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[3]` to be one of 'ss', 'hls', 'dash', 'other' or null." );
1157+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected `arg[3]` to be one of 'ss', 'hls', 'dash', 'other' or null." );
1158+ goto fail_free_uri ;
11571159 }
11581160 } else {
11591161 format_hint = FORMAT_HINT_NONE ;
@@ -1174,7 +1176,8 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
11741176 headers = arg ;
11751177 } else {
11761178invalid_headers :
1177- return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[4]` to be a map of strings or null." );
1179+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected `arg[4]` to be a map of strings or null." );
1180+ goto fail_free_uri ;
11781181 }
11791182 } else {
11801183 headers = NULL ;
@@ -1189,51 +1192,64 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
11891192 } else if (raw_std_value_is_string (arg )) {
11901193 pipeline = raw_std_string_dup (arg );
11911194 } else {
1192- return platch_respond_illegal_arg_std (responsehandle , "Expected `arg[5]` to be a string or null." );
1195+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected `arg[5]` to be a string or null." );
1196+ goto fail_free_uri ;
11931197 }
11941198 } else {
11951199 pipeline = NULL ;
11961200 }
11971201
11981202 if ((asset ? 1 : 0 ) + (uri ? 1 : 0 ) + (pipeline ? 1 : 0 ) != 1 ) {
1199- return platch_respond_illegal_arg_std (responsehandle , "Expected exactly one of `arg[0]`, `arg[2]` or `arg[5]` to be non-null." );
1203+ ok = platch_respond_illegal_arg_std (responsehandle , "Expected exactly one of `arg[0]`, `arg[2]` or `arg[5]` to be non-null." );
1204+ goto fail_free_pipeline ;
12001205 }
12011206
12021207 // Create our actual player (this doesn't initialize it)
12031208 if (asset != NULL ) {
1204- player = gstplayer_new_from_asset (flutterpi , asset , package_name , NULL );
1205-
12061209 // gstplayer_new_from_network will construct a file:// URI out of the
12071210 // asset path internally.
1208- free (asset );
1209- asset = NULL ;
1211+ player = gstplayer_new_from_asset (flutterpi , asset , package_name , NULL );
12101212 } else if (uri != NULL ) {
1213+ // gstplayer_new_from_network will dup the uri internally.
12111214 player = gstplayer_new_from_network (flutterpi , uri , format_hint , NULL );
1215+ } else if (pipeline != NULL ) {
1216+ // gstplayer_new_from_network will dup the pipeline internally.
1217+ player = gstplayer_new_from_pipeline (flutterpi , pipeline , NULL );
1218+ } else {
1219+ UNREACHABLE ();
1220+ }
12121221
1213- // gstplayer_new_from_network will dup the uri internally.
1222+ if (asset != NULL ) {
1223+ free (asset );
1224+ asset = NULL ;
1225+ }
1226+
1227+ if (package_name != NULL ) {
1228+ free (package_name );
1229+ package_name = NULL ;
1230+ }
1231+
1232+ if (uri != NULL ) {
12141233 free (uri );
12151234 uri = NULL ;
1216- } else if (pipeline != NULL ) {
1217- player = gstplayer_new_from_pipeline (flutterpi , pipeline , NULL );
1235+ }
12181236
1219- // gstplayer_new_from_network will dup the pipeline internally.
1237+ if ( pipeline != NULL ) {
12201238 free (pipeline );
12211239 pipeline = NULL ;
1222- } else {
1223- UNREACHABLE ();
12241240 }
12251241
12261242 if (player == NULL ) {
12271243 LOG_ERROR ("Couldn't create gstreamer video player.\n" );
1228- ok = EIO ;
1229- goto fail_respond_error ;
1244+ ok = platch_respond_native_error_std ( responsehandle , EIO ) ;
1245+ goto fail_destroy_player ;
12301246 }
12311247
12321248 // create a meta object so we can store the event channel name
12331249 // of a player with it
12341250 meta = create_meta (gstplayer_get_texture_id (player ), player );
12351251 if (meta == NULL ) {
1236- ok = ENOMEM ;
1252+ ok = platch_respond_native_error_std ( responsehandle , ENOMEM ) ;
12371253 goto fail_destroy_player ;
12381254 }
12391255
@@ -1258,12 +1274,14 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
12581274 // Set a receiver on the videoEvents event channel
12591275 ok = plugin_registry_set_receiver (meta -> event_channel_name , kStandardMethodCall , on_receive_evch );
12601276 if (ok != 0 ) {
1277+ platch_respond_native_error_std (responsehandle , ok );
12611278 goto fail_remove_player ;
12621279 }
12631280
12641281 // Finally, start initializing
12651282 ok = gstplayer_initialize (player );
12661283 if (ok != 0 ) {
1284+ platch_respond_native_error_std (responsehandle , ok );
12671285 goto fail_remove_receiver ;
12681286 }
12691287
@@ -1279,8 +1297,27 @@ static int on_create_v2(const struct raw_std_value *arg, FlutterPlatformMessageR
12791297fail_destroy_player :
12801298 gstplayer_destroy (player );
12811299
1282- fail_respond_error :
1283- return platch_respond_native_error_std (responsehandle , ok );
1300+ fail_free_pipeline :
1301+ if (pipeline != NULL ) {
1302+ free (pipeline );
1303+ }
1304+
1305+ fail_free_uri :
1306+ if (uri != NULL ) {
1307+ free (uri );
1308+ }
1309+
1310+ fail_free_package_name :
1311+ if (package_name != NULL ) {
1312+ free (package_name );
1313+ }
1314+
1315+ fail_free_asset :
1316+ if (asset != NULL ) {
1317+ free (asset );
1318+ }
1319+
1320+ return ok ;
12841321}
12851322
12861323static int on_dispose_v2 (const struct raw_std_value * arg , FlutterPlatformMessageResponseHandle * responsehandle ) {
0 commit comments