@@ -1045,7 +1045,10 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
1045
1045
1046
1046
end_of_function :
1047
1047
free (interface_path );
1048
- CloseHandle (device_handle );
1048
+
1049
+ if (device_handle != INVALID_HANDLE_VALUE ) {
1050
+ CloseHandle (device_handle );
1051
+ }
1049
1052
1050
1053
if (pp_data ) {
1051
1054
HidD_FreePreparsedData (pp_data );
@@ -1085,8 +1088,15 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
1085
1088
/* The user passed the right number of bytes. Use the buffer as-is. */
1086
1089
buf = (unsigned char * ) data ;
1087
1090
} else {
1088
- if (dev -> write_buf == NULL )
1091
+ if (dev -> write_buf == NULL ) {
1089
1092
dev -> write_buf = (unsigned char * ) malloc (dev -> output_report_length );
1093
+
1094
+ if (dev -> write_buf == NULL ) {
1095
+ register_string_error (dev , L"hid_write/malloc" );
1096
+ goto end_of_function ;
1097
+ }
1098
+ }
1099
+
1090
1100
buf = dev -> write_buf ;
1091
1101
memcpy (buf , data , length );
1092
1102
memset (buf + length , 0 , dev -> output_report_length - length );
@@ -1253,8 +1263,15 @@ int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *dev, const u
1253
1263
buf = (unsigned char * ) data ;
1254
1264
length_to_send = length ;
1255
1265
} else {
1256
- if (dev -> feature_buf == NULL )
1266
+ if (dev -> feature_buf == NULL ) {
1257
1267
dev -> feature_buf = (unsigned char * ) malloc (dev -> feature_report_length );
1268
+
1269
+ if (dev -> feature_buf == NULL ) {
1270
+ register_string_error (dev , L"hid_send_feature_report/malloc" );
1271
+ return -1 ;
1272
+ }
1273
+ }
1274
+
1258
1275
buf = dev -> feature_buf ;
1259
1276
memcpy (buf , data , length );
1260
1277
memset (buf + length , 0 , dev -> feature_report_length - length );
@@ -1347,8 +1364,15 @@ int HID_API_EXPORT HID_API_CALL hid_send_output_report(hid_device* dev, const un
1347
1364
buf = (unsigned char * ) data ;
1348
1365
length_to_send = length ;
1349
1366
} else {
1350
- if (dev -> write_buf == NULL )
1367
+ if (dev -> write_buf == NULL ) {
1351
1368
dev -> write_buf = (unsigned char * ) malloc (dev -> output_report_length );
1369
+
1370
+ if (dev -> write_buf == NULL ) {
1371
+ register_string_error (dev , L"hid_send_output_report/malloc" );
1372
+ return -1 ;
1373
+ }
1374
+ }
1375
+
1352
1376
buf = dev -> write_buf ;
1353
1377
memcpy (buf , data , length );
1354
1378
memset (buf + length , 0 , dev -> output_report_length - length );
0 commit comments