Skip to content

Commit 775a4b3

Browse files
committed
[core] fix various string memory leaks
* Also fix version report on update * Also add a popup when no update is available
1 parent b5004d5 commit 775a4b3

File tree

10 files changed

+58
-38
lines changed

10 files changed

+58
-38
lines changed

examples/profile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,12 @@ long profile_open_file(const char * filespec,
251251
expanded_filename = malloc(len);
252252
if (expanded_filename == 0) {
253253
profile_free_file(prf);
254+
free(home_env);
254255
return errno;
255256
}
256257
if (home_env) {
257258
strcpy(expanded_filename, home_env);
259+
free(home_env);
258260
strcat(expanded_filename, filespec+1);
259261
} else
260262
memcpy(expanded_filename, filespec, len);

examples/wdi-simple.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#endif
88

99
VS_VERSION_INFO VERSIONINFO
10-
FILEVERSION 1,3,0,702
11-
PRODUCTVERSION 1,3,0,702
10+
FILEVERSION 1,3,0,703
11+
PRODUCTVERSION 1,3,0,703
1212
FILEFLAGSMASK 0x17L
1313
#ifdef _DEBUG
1414
FILEFLAGS 0x1L
@@ -25,13 +25,13 @@ BEGIN
2525
BEGIN
2626
VALUE "CompanyName", "akeo.ie"
2727
VALUE "FileDescription", "WDI-Simple"
28-
VALUE "FileVersion", "1.3.0.702"
28+
VALUE "FileVersion", "1.3.0.703"
2929
VALUE "InternalName", "WDI-Simple"
3030
VALUE "LegalCopyright", "� 2010-2017 Pete Batard (LGPL v3)"
3131
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/lesser.html"
3232
VALUE "OriginalFilename", "wdi-simple.exe"
3333
VALUE "ProductName", "WDI-Simple"
34-
VALUE "ProductVersion", "1.3.0.702"
34+
VALUE "ProductVersion", "1.3.0.703"
3535
VALUE "Comments", "http://libwdi.akeo.ie"
3636
END
3737
END

examples/zadic.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ END
5656
//
5757

5858
VS_VERSION_INFO VERSIONINFO
59-
FILEVERSION 1,3,0,702
60-
PRODUCTVERSION 1,3,0,702
59+
FILEVERSION 1,3,0,703
60+
PRODUCTVERSION 1,3,0,703
6161
FILEFLAGSMASK 0x17L
6262
#ifdef _DEBUG
6363
FILEFLAGS 0x1L
@@ -74,13 +74,13 @@ BEGIN
7474
BEGIN
7575
VALUE "CompanyName", "akeo.ie"
7676
VALUE "FileDescription", "Zadic"
77-
VALUE "FileVersion", "1.3.0.702"
77+
VALUE "FileVersion", "1.3.0.703"
7878
VALUE "InternalName", "Zadic"
7979
VALUE "LegalCopyright", "� 2010-2017 Pete Batard (LGPL v3)"
8080
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/lesser.html"
8181
VALUE "OriginalFilename", "zadic.exe"
8282
VALUE "ProductName", "Zadic"
83-
VALUE "ProductVersion", "1.3.0.702"
83+
VALUE "ProductVersion", "1.3.0.703"
8484
VALUE "Comments", "http://libwdi.akeo.ie"
8585
END
8686
END

examples/zadig.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,10 @@ INT_PTR CALLBACK main_callback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP
12751275
}
12761276
return (INT_PTR)TRUE;
12771277

1278+
case UM_NO_UPDATE:
1279+
notification(MSG_INFO, NULL, "Update check", "No new version of Zadig was found");
1280+
break;
1281+
12781282
case WM_INITDIALOG:
12791283
SetUpdateCheck();
12801284
// Setup options
@@ -1793,7 +1797,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
17931797
if ((msg.message == WM_SYSKEYDOWN) && (msg.wParam == 'Z')) {
17941798
for (r = TRUE, i = 0; i<ARRAYSIZE(system_dir); i++) {
17951799
path[0] = 0;
1796-
safe_strcpy(path, MAX_PATH, getenvU("WINDIR"));
1800+
tmp = getenvU("WINDIR");
1801+
safe_strcpy(path, MAX_PATH, tmp);
1802+
safe_free(tmp);
17971803
safe_strcat(path, MAX_PATH, "\\");
17981804
safe_strcat(path, MAX_PATH, system_dir[i]);
17991805
safe_strcat(path, MAX_PATH, "\\libusb-1.0.dll");
@@ -1823,6 +1829,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
18231829
DispatchMessage(&msg);
18241830
}
18251831

1832+
safe_free(update.download_url);
1833+
safe_free(update.release_notes);
18261834
CloseHandle(mutex);
18271835
#ifdef _CRTDBG_MAP_ALLOC
18281836
_CrtDumpMemoryLeaks();

examples/zadig.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#define FIELD_ORANGE RGB(255,240,200)
6060
#define ARROW_GREEN RGB(92,228,65)
6161
#define ARROW_ORANGE RGB(253,143,56)
62-
#define APP_VERSION "Zadig 2.3.702"
62+
#define APP_VERSION "Zadig 2.3.703"
6363

6464
// These are used to flag end users about the driver they are going to replace
6565
enum driver_type {
@@ -90,6 +90,7 @@ enum user_message_type {
9090
UM_LOGGER_EVENT,
9191
UM_DOWNLOAD_INIT,
9292
UM_DOWNLOAD_EXIT,
93+
UM_NO_UPDATE
9394
};
9495

9596
// WCID states

examples/zadig.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ END
246246
//
247247

248248
VS_VERSION_INFO VERSIONINFO
249-
FILEVERSION 2,3,682,702
250-
PRODUCTVERSION 2,3,682,702
249+
FILEVERSION 2,3,682,703
250+
PRODUCTVERSION 2,3,682,703
251251
FILEFLAGSMASK 0x17L
252252
#ifdef _DEBUG
253253
FILEFLAGS 0x1L
@@ -264,13 +264,13 @@ BEGIN
264264
BEGIN
265265
VALUE "CompanyName", "akeo.ie"
266266
VALUE "FileDescription", "Zadig"
267-
VALUE "FileVersion", "2.3.702"
267+
VALUE "FileVersion", "2.3.703"
268268
VALUE "InternalName", "Zadig"
269269
VALUE "LegalCopyright", "� 2010-2017 Pete Batard (GPL v3)"
270270
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
271271
VALUE "OriginalFilename", "zadig.exe"
272272
VALUE "ProductName", "Zadig"
273-
VALUE "ProductVersion", "2.3.702"
273+
VALUE "ProductVersion", "2.3.703"
274274
VALUE "Comments", "http://libwdi.akeo.ie"
275275
END
276276
END

examples/zadig_net.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ static DWORD WINAPI CheckForUpdatesThread(LPVOID param)
616616
Sleep(15000);
617617
}
618618
download_new_version();
619+
} else if (force_update_check) {
620+
PostMessage(hMain, UM_NO_UPDATE, 0, 0);
619621
}
620622
force_update_check = FALSE;
621623
update_check_in_progress = FALSE;

examples/zadig_stdlg.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,11 @@ INT_PTR CALLBACK new_version_callback(HWND hDlg, UINT message, WPARAM wParam, LP
10451045
SendMessageA(hNotes, EM_SETTEXTEX, (WPARAM)&friggin_microsoft_unicode_amateurs, (LPARAM)update.release_notes);
10461046
SendMessage(hNotes, EM_SETSEL, -1, -1);
10471047
SendMessage(hNotes, EM_SETEVENTMASK, 0, ENM_LINK);
1048-
safe_sprintf(tmp, sizeof(tmp), "Your version: %d.%d.%d (Build %d)",
1049-
application_version[0], application_version[1], application_version[2], application_version[3]);
1048+
safe_sprintf(tmp, sizeof(tmp), "Your version: %d.%d (Build %d)",
1049+
application_version[0], application_version[1], application_version[2]);
10501050
SetWindowTextU(GetDlgItem(hDlg, IDC_YOUR_VERSION), tmp);
1051-
safe_sprintf(tmp, sizeof(tmp), "Latest version: %d.%d.%d (Build %d)",
1052-
update.version[0], update.version[1], update.version[2], update.version[3]);
1051+
safe_sprintf(tmp, sizeof(tmp), "Latest version: %d.%d (Build %d)",
1052+
update.version[0], update.version[1], update.version[2]);
10531053
SetWindowTextU(GetDlgItem(hDlg, IDC_LATEST_VERSION), tmp);
10541054
SetWindowTextU(GetDlgItem(hDlg, IDC_DOWNLOAD_URL), update.download_url);
10551055
SendMessage(GetDlgItem(hDlg, IDC_PROGRESS), PBM_SETRANGE, 0, (MAX_PROGRESS<<16) & 0xFFFF0000);
@@ -1090,7 +1090,6 @@ INT_PTR CALLBACK new_version_callback(HWND hDlg, UINT message, WPARAM wParam, LP
10901090
si.cb = sizeof(si);
10911091
if (!CreateProcessU(filepath, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
10921092
print_status(0, TRUE, "Failed to launch new application");
1093-
// TODO: produce a message box and add a retry in case the file is in use
10941093
dprintf("Failed to launch new application: %s\n", WindowsErrorString());
10951094
} else {
10961095
print_status(0, FALSE, "Launching new application...");

libwdi/libwdi.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

libwdi/libwdi.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ END
5050
//
5151

5252
VS_VERSION_INFO VERSIONINFO
53-
FILEVERSION 1,3,0,702
54-
PRODUCTVERSION 1,3,0,702
53+
FILEVERSION 1,3,0,703
54+
PRODUCTVERSION 1,3,0,703
5555
FILEFLAGSMASK 0x17L
5656
#ifdef _DEBUG
5757
FILEFLAGS 0x1L
@@ -68,13 +68,13 @@ BEGIN
6868
BEGIN
6969
VALUE "CompanyName", "akeo.ie"
7070
VALUE "FileDescription", "libwdi: Windows Driver Installer Library"
71-
VALUE "FileVersion", "1.3.0.702"
71+
VALUE "FileVersion", "1.3.0.703"
7272
VALUE "InternalName", "libwdi"
7373
VALUE "LegalCopyright", "� 2010-2017 Pete Batard (LGPL v3)"
7474
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/lesser.html"
7575
VALUE "OriginalFilename", "libwdi"
7676
VALUE "ProductName", "libwdi"
77-
VALUE "ProductVersion", "1.3.0.702"
77+
VALUE "ProductVersion", "1.3.0.703"
7878
VALUE "Comments", "http://libwdi.akeo.ie"
7979
END
8080
END

0 commit comments

Comments
 (0)