[code] improve error checks on free

This commit is contained in:
akallabeth 2024-01-19 09:22:09 +01:00 committed by akallabeth
parent 8d45b3fa66
commit 575d42312a
3 changed files with 13 additions and 5 deletions

View File

@ -5276,8 +5276,15 @@ static int freerdp_client_settings_parse_command_line_arguments_int(
return status; return status;
} }
static void argv_free(int argc, char* argv[]) static void argv_free(int* pargc, char** pargv[])
{ {
WINPR_ASSERT(pargc);
WINPR_ASSERT(pargv);
const int argc = *pargc;
char** argv = *pargv;
*pargc = 0;
*pargv = NULL;
if (!argv) if (!argv)
return; return;
for (int x = 0; x < argc; x++) for (int x = 0; x < argc; x++)
@ -5360,7 +5367,7 @@ static BOOL args_from_fp(FILE* fp, int* aargc, char** aargv[], const char* file,
fail: fail:
fclose(fp); fclose(fp);
if (!success) if (!success)
argv_free(*aargc, *aargv); argv_free(aargc, aargv);
return success; return success;
} }
@ -5414,7 +5421,7 @@ static BOOL args_from_env(const char* name, int* aargc, char** aargv[], const ch
cleanup: cleanup:
free(env); free(env);
if (!success) if (!success)
argv_free(*aargc, *aargv); argv_free(aargc, aargv);
return success; return success;
} }
@ -5478,7 +5485,7 @@ int freerdp_client_settings_parse_command_line_arguments_ex(
settings, argc, argv, allowUnknown, largs, lcount, handle_option, handle_userdata); settings, argc, argv, allowUnknown, largs, lcount, handle_option, handle_userdata);
fail: fail:
free(largs); free(largs);
argv_free(aargc, aargv); argv_free(&aargc, &aargv);
return res; return res;
} }

View File

@ -288,6 +288,7 @@ fail:
} }
free(bind_pdu.p_context_elem.p_cont_elem); free(bind_pdu.p_context_elem.p_cont_elem);
bind_pdu.p_context_elem.p_cont_elem = NULL;
Stream_Free(buffer, TRUE); Stream_Free(buffer, TRUE);
return (status > 0) ? 1 : -1; return (status > 0) ? 1 : -1;

View File

@ -355,9 +355,9 @@ static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 form
char* utfString = char* utfString =
ConvertWCharNToUtf8Alloc(&pSrcData.pv[1], SrcSize / sizeof(WCHAR), NULL); ConvertWCharNToUtf8Alloc(&pSrcData.pv[1], SrcSize / sizeof(WCHAR), NULL);
free(pSrcData.pv); free(pSrcData.pv);
pSrcData.cpc = utfString;
if (!utfString) if (!utfString)
goto fail; goto fail;
pSrcData.cpc = utfString;
} }
} }