[VM/IO] Fix error path in SocketAddress::GetSockAddr

Dart_TypedDataReleaseData was not called in an error path.

Should fix https://github.com/dart-lang/sdk/issues/60421

TEST=tests/standalone/io/datagram_error_test.dart

Change-Id: I1935af1c5beed9d696a0543d0e97f2d549743879
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418701
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
diff --git a/runtime/bin/socket_base.cc b/runtime/bin/socket_base.cc
index 40357d0..c69b544 100644
--- a/runtime/bin/socket_base.cc
+++ b/runtime/bin/socket_base.cc
@@ -113,6 +113,7 @@
   }
   if ((data_type != Dart_TypedData_kUint8) ||
       ((len != sizeof(in_addr)) && (len != sizeof(in6_addr)))) {
+    Dart_TypedDataReleaseData(obj);
     Dart_PropagateError(Dart_NewApiError("Unexpected type for socket address"));
   }
   memset(reinterpret_cast<void*>(addr), 0, sizeof(RawAddr));
diff --git a/tests/standalone/io/datagram_error.dart b/tests/standalone/io/datagram_error.dart
new file mode 100644
index 0000000..fd54aa4
--- /dev/null
+++ b/tests/standalone/io/datagram_error.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2025, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Dart test program for testing error path in datagram bind call.
+
+import 'dart:io';
+
+import "package:expect/expect.dart";
+
+void main() async {
+  try {
+    final socket = await RawDatagramSocket.bind(
+      InternetAddress('/tmp/test_socket', type: InternetAddressType.unix),
+      0,
+    );
+    Expect.fail(
+      "Should not reach this: "
+      "the bind call above should have failed",
+    );
+    socket.listen((data) {
+      print(data);
+    });
+  } catch (e) {
+    Expect.fail(
+      "Should not reach this: "
+      "the bind call above throws unhandled exception",
+    );
+  }
+}
diff --git a/tests/standalone/io/datagram_error_test.dart b/tests/standalone/io/datagram_error_test.dart
new file mode 100644
index 0000000..f5fa6b8
--- /dev/null
+++ b/tests/standalone/io/datagram_error_test.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2025, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Dart test program for testing error path in datagram bind call.
+//
+// OtherResources=datagram_error.dart
+
+import 'dart:io';
+
+import "package:expect/expect.dart";
+import 'package:path/path.dart' as path;
+
+void main() async {
+  var sdkPath = path.absolute(path.dirname(Platform.executable));
+  var dartPath = path.absolute(
+    sdkPath,
+    Platform.isWindows ? 'dart.exe' : 'dart',
+  );
+  // Get the Dart script file that generates output.
+  var scriptFile = new File(
+    Platform.script.resolve("datagram_error.dart").toFilePath(),
+  );
+  var args = <String>[scriptFile.path];
+  ProcessResult syncResult = Process.runSync(dartPath, args);
+  Expect.notEquals(0, syncResult.exitCode);
+  Expect.stringEquals(
+    syncResult.stderr,
+    "Unexpected type for socket address" + Platform.lineTerminator,
+  );
+}