Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
Recently, I seem to have forgotten that VLAs need to be freed, too.
  • Loading branch information
nmlgc committed Aug 20, 2013
1 parent 089896a commit 2b7c110
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
2 changes: 0 additions & 2 deletions thcrap/src/bp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ int BP_file_name(x86_reg_t *regs, json_t *bp_info)
if(fr->name) {
file_rep_clear(fr);
}

fn_len = strlen(*file_name) + 1;
fr->name = EnsureUTF8(*file_name, fn_len);
fr->rep_buffer = stack_game_file_resolve(fr->name, &fr->rep_size);
fr->hooks = patchhooks_build(fr->name);
if(fr->hooks) {
size_t diff_fn_len = fn_len + strlen(".jdiff") + 1;
size_t diff_size = 0;

{
VLA(char, diff_fn, diff_fn_len);
strcpy(diff_fn, fr->name);
Expand Down
10 changes: 4 additions & 6 deletions thcrap/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ json_t* identify(const char *exe_fn)
json_object_set(run_cfg, "build", json_array_get(id_array, 1));

{
size_t ver_fn_len = strlen(game) + 1 + strlen(".js") + 1;
VLA(char, ver_fn, ver_fn_len);

log_printf("→ %s %s %s\n", game, build, variety);

if(stricmp(PathFindExtensionA(game), ".js")) {
size_t ver_fn_len = strlen(game) + 1 + strlen(".js") + 1;
VLA(char, ver_fn, ver_fn_len);
sprintf(ver_fn, "%s.js", game);
run_ver = stack_json_resolve(ver_fn, NULL);
VLA_FREE(ver_fn);
} else {
run_ver = stack_json_resolve(game, NULL);
}
Expand Down Expand Up @@ -239,7 +239,6 @@ int thcrap_init(const char *setup_fn)
json_decref(run_cfg);
run_cfg = run_ver;
}

{
// Copy format links from formats.js
json_t *game_formats = json_object_get(run_cfg, "formats");
Expand All @@ -258,7 +257,6 @@ int thcrap_init(const char *setup_fn)
json_decref(formats_js);
}
}

log_printf("Initializing patches...\n");
{
json_t *patches = json_object_get(run_cfg, "patches");
Expand Down
3 changes: 1 addition & 2 deletions thcrap/src/textdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ HFONT WINAPI textdisp_CreateFontA(
{
int replaced = 0;
const char *string_font;
json_t *run_font;

iCharSet = DEFAULT_CHARSET;

Expand All @@ -40,7 +39,7 @@ HFONT WINAPI textdisp_CreateFontA(
pszFaceName = string_font;
replaced = 1;
} else {
run_font = json_object_get(run_cfg, "font");
json_t *run_font = json_object_get(run_cfg, "font");
if(json_is_string(run_font)) {
pszFaceName = json_string_value(run_font);
replaced = 1;
Expand Down
2 changes: 1 addition & 1 deletion thcrap_tsa/src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int layout_match_set(json_t *arr, size_t ind, const char *str, size_t len)
strncpy(arg, str, len);
arg[len] = 0;
json_str = json_string(arg);

VLA_FREE(arg);
return json_array_set_expand(arr, ind, json_str);
}
}
Expand Down
1 change: 0 additions & 1 deletion thcrap_tsa/src/thcrap_tsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ typedef void (*EncryptionFunc_t)(
/// ------
/// Spells
/// ------

/**
* Reads a spell card ID.
*
Expand Down
6 changes: 4 additions & 2 deletions win32_utf8/src/kernel32_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ DWORD WINAPI GetEnvironmentVariableU(
VLA(wchar_t, lpBuffer_w, nSize);
StringToUTF16(lpName_w, lpName, lpName_len);

ret = GetEnvironmentVariableW(lpName_w, lpBuffer_w, nSize);
GetEnvironmentVariableW(lpName_w, lpBuffer_w, nSize);
// Return the converted size (!)
return StringToUTF8(lpBuffer, lpBuffer_w, nSize);
ret = StringToUTF8(lpBuffer, lpBuffer_w, nSize);
VLA_FREE(lpBuffer_w);
return ret;
}

DWORD WINAPI GetModuleFileNameU(
Expand Down

0 comments on commit 2b7c110

Please sign in to comment.