@@ -474,10 +474,12 @@ int get_version_info(int driver_type, VS_FIXEDFILEINFO* driver_info)
474474 }
475475 r = check_dir (tmpdir , TRUE);
476476 if (r != WDI_SUCCESS ) {
477+ free (tmpdir );
477478 return r ;
478479 }
479480
480481 safe_strcpy (filename , MAX_PATH , tmpdir );
482+ free (tmpdir );
481483 safe_strcat (filename , MAX_PATH , "\\" );
482484 if (resource [res ].name != NULL ) // Stupid Clang!
483485 safe_strcat (filename , MAX_PATH , resource [res ].name );
@@ -1037,7 +1039,7 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
10371039 const char * inf_ext = ".inf" ;
10381040 const char * vendor_name = NULL ;
10391041 const char * cat_list [CAT_LIST_MAX_ENTRIES + 1 ];
1040- char inf_path [MAX_PATH ], cat_path [MAX_PATH ], hw_id [40 ], cert_subject [64 ];
1042+ char drv_path [ MAX_PATH ], inf_path [MAX_PATH ], cat_path [MAX_PATH ], hw_id [40 ], cert_subject [64 ];
10411043 char * strguid , * token , * cat_name = NULL , * dst = NULL , * cat_in_copy = NULL ;
10421044 wchar_t * wdst = NULL ;
10431045 int i , nb_entries , driver_type = WDI_WINUSB , r = WDI_ERROR_OTHER ;
@@ -1070,19 +1072,23 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
10701072 MUTEX_RETURN (WDI_ERROR_INVALID_PARAM );
10711073 }
10721074
1073- // Try to use the user's temp dir if no path is provided
1074- if ((path == NULL ) || (path [0 ] == 0 )) {
1075- path = getenvU ("TEMP" );
1076- if (path == NULL ) {
1075+ if (path != NULL ) {
1076+ static_strcpy (drv_path , path );
1077+ } else {
1078+ // Try to use the user's temp dir
1079+ char * tmp = getenvU ("TEMP" );
1080+ if (tmp == NULL ) {
10771081 wdi_err ("no path provided and unable to use TEMP" );
10781082 MUTEX_RETURN (WDI_ERROR_INVALID_PARAM );
10791083 } else {
1080- wdi_info ("no path provided - extracting to '%s'" , path );
1084+ static_strcpy (drv_path , tmp );
1085+ free (tmp );
1086+ wdi_info ("no path provided - extracting to '%s'" , drv_path );
10811087 }
10821088 }
10831089
10841090 // Try to create directory if it doesn't exist
1085- r = check_dir (path , TRUE);
1091+ r = check_dir (drv_path , TRUE);
10861092 if (r != WDI_SUCCESS ) {
10871093 MUTEX_RETURN (r );
10881094 }
@@ -1124,26 +1130,26 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
11241130 // For custom drivers, as we cannot autogenerate the inf, simply extract binaries
11251131 if (driver_type == WDI_USER ) {
11261132 wdi_info ("custom driver - extracting binaries only (no inf/cat creation)" );
1127- MUTEX_RETURN (extract_binaries (path ));
1133+ MUTEX_RETURN (extract_binaries (drv_path ));
11281134 }
11291135
11301136 if (device_info -> desc == NULL ) {
11311137 wdi_err ("no device ID was given for the device - aborting" );
11321138 MUTEX_RETURN (WDI_ERROR_INVALID_PARAM );
11331139 }
11341140
1135- r = extract_binaries (path );
1141+ r = extract_binaries (drv_path );
11361142 if (r != WDI_SUCCESS ) {
11371143 MUTEX_RETURN (r );
11381144 }
11391145
11401146 // Populate the inf and cat names & paths
1141- if ( (strlen (path ) >= MAX_PATH ) || (strlen (inf_name ) >= MAX_PATH ) ||
1142- ((strlen (path ) + strlen (inf_name )) > (MAX_PATH - 2 )) ) {
1143- wdi_err ("qualified path for inf file is too long: '%s\\%s" , path , inf_name );
1147+ if ( (strlen (drv_path ) >= MAX_PATH ) || (strlen (inf_name ) >= MAX_PATH ) ||
1148+ ((strlen (drv_path ) + strlen (inf_name )) > (MAX_PATH - 2 )) ) {
1149+ wdi_err ("qualified path for inf file is too long: '%s\\%s" , drv_path , inf_name );
11441150 MUTEX_RETURN (WDI_ERROR_RESOURCE );
11451151 }
1146- safe_strcpy (inf_path , sizeof (inf_path ), path );
1152+ safe_strcpy (inf_path , sizeof (inf_path ), drv_path );
11471153 safe_strcat (inf_path , sizeof (inf_path ), "\\" );
11481154 safe_strcat (inf_path , sizeof (inf_path ), inf_name );
11491155 safe_strcpy (cat_path , sizeof (cat_path ), inf_path );
@@ -1302,7 +1308,7 @@ int LIBWDI_API wdi_prepare_driver(struct wdi_device_info* device_info, const cha
13021308 sprintf (cert_subject , "CN=%s (libwdi autogenerated)" , hw_id );
13031309
13041310 // Failures on the following aren't fatal errors
1305- if (!CreateCat (cat_path , hw_id , path , cat_list , nb_entries )) {
1311+ if (!CreateCat (cat_path , hw_id , drv_path , cat_list , nb_entries )) {
13061312 wdi_warn ("could not create cat file" );
13071313 } else if ((options != NULL ) && (!options -> disable_signing ) && (!SelfSignFile (cat_path ,
13081314 (options -> cert_subject != NULL )?options -> cert_subject :cert_subject ))) {
@@ -1445,7 +1451,9 @@ static int install_driver_internal(void* arglist)
14451451
14461452 // Try to use the user's temp dir if no path is provided
14471453 if ((params -> path == NULL ) || (params -> path [0 ] == 0 )) {
1448- static_strcpy (path , getenvU ("TEMP" ));
1454+ char * tmp = getenvU ("TEMP" );
1455+ static_strcpy (path , tmp );
1456+ free (tmp );
14491457 wdi_info ("no path provided - installing from '%s'" , path );
14501458 } else {
14511459 static_strcpy (path , params -> path );
0 commit comments