[compiler] add WINPR_ATTR_MALLOC

Add WINPR_ATTR_MALLOC checks to allocating functions to help compilers
find memory leaks or allocation mismatches
This commit is contained in:
akallabeth 2024-09-12 17:07:16 +02:00
parent fb5934007a
commit afff514ca7
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
16 changed files with 78 additions and 32 deletions

View File

@ -31,11 +31,19 @@ extern "C"
typedef struct rdp_assistance_file rdpAssistanceFile;
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API BYTE* freerdp_assistance_hex_string_to_bin(const void* str, size_t* size);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_assistance_bin_to_hex_string(const void* data, size_t size);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_assistance_generate_pass_stub(DWORD flags);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_assistance_construct_expert_blob(const char* name, const char* pass);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API BYTE* freerdp_assistance_encrypt_pass_stub(const char* password,
const char* passStub,
size_t* pEncryptedSize);

View File

@ -205,7 +205,7 @@ extern "C"
FREERDP_API UINT32 audio_format_compute_time_length(const AUDIO_FORMAT* format, size_t size);
FREERDP_API char* audio_format_get_tag_string(UINT16 wFormatTag);
FREERDP_API const char* audio_format_get_tag_string(UINT16 wFormatTag);
FREERDP_API void audio_format_print(wLog* log, DWORD level, const AUDIO_FORMAT* format);
FREERDP_API void audio_formats_print(wLog* log, DWORD level, const AUDIO_FORMAT* formats,

View File

@ -22,6 +22,7 @@
#ifndef FREERDP_CODEC_COLOR_H
#define FREERDP_CODEC_COLOR_H
#include <winpr/crt.h>
#include <freerdp/api.h>
#ifdef __cplusplus
@ -286,6 +287,7 @@ typedef struct gdi_palette gdiPalette;
* @return A buffer allocated with winpr_aligned_malloc(width * height, 16)
* if successful, NULL otherwise.
*/
WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height,
const BYTE* WINPR_RESTRICT data);

View File

@ -54,15 +54,23 @@ extern "C"
FREERDP_API BOOL freerdp_certificate_is_rsa(const rdpCertificate* certificate);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_hash(const rdpCertificate* certificate,
const char* hash, size_t* plength);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_fingerprint_by_hash(const rdpCertificate* certificate,
const char* hash);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char*
freerdp_certificate_get_fingerprint_by_hash_ex(const rdpCertificate* certificate,
const char* hash, BOOL separator);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_fingerprint(const rdpCertificate* certificate);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_pem(const rdpCertificate* certificate,
size_t* pLength);
@ -75,15 +83,24 @@ extern "C"
* @return A newly allocated string containing the requested PEM (free to deallocate) or NULL
* @since version 3.8.0
*/
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_pem_ex(const rdpCertificate* certificate,
size_t* pLength, BOOL withCertChain);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API BYTE* freerdp_certificate_get_der(const rdpCertificate* certificate,
size_t* pLength);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_subject(const rdpCertificate* certificate);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_issuer(const rdpCertificate* certificate);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_upn(const rdpCertificate* certificate);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_email(const rdpCertificate* certificate);
/**
@ -93,13 +110,17 @@ extern "C"
* @return A newly allocated string containing the date, use \b free to deallocate
* @since version 3.8.0
*/
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_validity(const rdpCertificate* certificate,
BOOL startDate);
FREERDP_API WINPR_MD_TYPE freerdp_certificate_get_signature_alg(const rdpCertificate* cert);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_common_name(const rdpCertificate* cert,
size_t* plength);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char** freerdp_certificate_get_dns_names(const rdpCertificate* cert, size_t* pcount,
size_t** pplengths);
FREERDP_API void freerdp_certificate_free_dns_names(size_t count, size_t* lengths,
@ -115,6 +136,7 @@ extern "C"
FREERDP_API BOOL freerdp_certificate_is_rdp_security_compatible(const rdpCertificate* cert);
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_certificate_get_param(const rdpCertificate* cert,
enum FREERDP_CERT_PARAM what, size_t* psize);

View File

@ -126,6 +126,13 @@ extern "C"
*/
FREERDP_API BOOL pf_server_config_dump(const char* file);
/**
* @brief pf_server_config_free Releases all resources associated with proxyConfig
*
* @param config A pointer to the proxyConfig to clean up. Might be NULL.
*/
FREERDP_API void pf_server_config_free(proxyConfig* config);
/**
* @brief server_config_load_ini Create a proxyConfig from a already loaded
* INI file.
@ -134,6 +141,7 @@ extern "C"
*
* @return A proxyConfig or NULL in case of failure.
*/
WINPR_ATTR_MALLOC(pf_server_config_free, 1)
FREERDP_API proxyConfig* server_config_load_ini(wIniFile* ini);
/**
* @brief pf_server_config_load_file Create a proxyConfig from a INI file found at path.
@ -142,6 +150,7 @@ extern "C"
*
* @return A proxyConfig or NULL in case of failure.
*/
WINPR_ATTR_MALLOC(pf_server_config_free, 1)
FREERDP_API proxyConfig* pf_server_config_load_file(const char* path);
/**
@ -152,6 +161,7 @@ extern "C"
*
* @return A proxyConfig or NULL in case of failure.
*/
WINPR_ATTR_MALLOC(pf_server_config_free, 1)
FREERDP_API proxyConfig* pf_server_config_load_buffer(const char* buffer);
/**
@ -161,13 +171,6 @@ extern "C"
*/
FREERDP_API void pf_server_config_print(const proxyConfig* config);
/**
* @brief pf_server_config_free Releases all resources associated with proxyConfig
*
* @param config A pointer to the proxyConfig to clean up. Might be NULL.
*/
FREERDP_API void pf_server_config_free(proxyConfig* config);
/**
* @brief pf_config_required_plugins_count
*

View File

@ -80,6 +80,12 @@ extern "C"
#define FREERDP_SETTINGS_SERVER_MODE 0x00000001
#define FREERDP_SETTINGS_REMOTE_MODE 0x00000002
/** \brief Free a settings struct with all data in it
*
* \param settings A pointer to the settings to free, May be NULL
*/
FREERDP_API void freerdp_settings_free(rdpSettings* settings);
/** \brief creates a new setting struct
*
* \param flags Flags for creation, use \b FREERDP_SETTINGS_SERVER_MODE for server settings, 0
@ -87,6 +93,7 @@ extern "C"
*
* \return A newly allocated settings struct or NULL
*/
WINPR_ATTR_MALLOC(freerdp_settings_free, 1)
FREERDP_API rdpSettings* freerdp_settings_new(DWORD flags);
/** \brief Creates a deep copy of settings
@ -95,6 +102,7 @@ extern "C"
*
* \return A newly allocated copy of \b settings or NULL
*/
WINPR_ATTR_MALLOC(freerdp_settings_free, 1)
FREERDP_API rdpSettings* freerdp_settings_clone(const rdpSettings* settings);
/** \brief Deep copies settings from \b src to \b dst
@ -122,12 +130,6 @@ extern "C"
FREERDP_API BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src,
SSIZE_T id);
/** \brief Free a settings struct with all data in it
*
* \param settings A pointer to the settings to free, May be NULL
*/
FREERDP_API void freerdp_settings_free(rdpSettings* settings);
/** \brief Dumps the contents of a settings struct to a WLog logger
*
* \param log The logger to write to, must not be NULL
@ -148,10 +150,14 @@ extern "C"
FREERDP_API BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* src,
const rdpSettings* other);
FREERDP_API ADDIN_ARGV* freerdp_addin_argv_new(size_t argc, const char* argv[]);
FREERDP_API ADDIN_ARGV* freerdp_addin_argv_clone(const ADDIN_ARGV* args);
FREERDP_API void freerdp_addin_argv_free(ADDIN_ARGV* args);
WINPR_ATTR_MALLOC(freerdp_addin_argv_free, 1)
FREERDP_API ADDIN_ARGV* freerdp_addin_argv_new(size_t argc, const char* argv[]);
WINPR_ATTR_MALLOC(freerdp_addin_argv_free, 1)
FREERDP_API ADDIN_ARGV* freerdp_addin_argv_clone(const ADDIN_ARGV* args);
FREERDP_API BOOL freerdp_addin_argv_add_argument(ADDIN_ARGV* args, const char* argument);
FREERDP_API BOOL freerdp_addin_argv_add_argument_ex(ADDIN_ARGV* args, const char* argument,
size_t len);
@ -686,7 +692,7 @@ extern "C"
*
* \return A pointer to \b buffer for success, NULL otherwise
*/
FREERDP_API char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer,
FREERDP_API const char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer,
size_t length);
/** \brief Returns a stringified representation of the RDP protocol version.
@ -721,6 +727,7 @@ extern "C"
* @return The current configuration path or \b NULL
* @since version 3.6.0
*/
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_settings_get_config_path(void);
#ifdef __cplusplus

View File

@ -40,6 +40,7 @@
*
* @return The token string or \b NULL
*/
WINPR_ATTR_MALLOC(free, 1)
FREERDP_API char* freerdp_utils_aad_get_access_token(wLog* log, const char* data, size_t length);
#endif

View File

@ -70,6 +70,6 @@ FREERDP_API BOOL freerdp_http_request(const char* url, const char* body, long* s
BYTE** response, size_t* response_length);
FREERDP_API const char* freerdp_http_status_string(long status);
FREERDP_API char* freerdp_http_status_string_format(long status, char* buffer, size_t size);
FREERDP_API const char* freerdp_http_status_string_format(long status, char* buffer, size_t size);
#endif /* FREERDP_UTILS_HTTP_H */

View File

@ -34,8 +34,8 @@ extern "C"
FREERDP_API int freerdp_interruptible_getc(rdpContext* context, FILE* file);
FREERDP_API SSIZE_T freerdp_interruptible_get_line(rdpContext* context, char** lineptr,
size_t* size, FILE* stream);
FREERDP_API char* freerdp_passphrase_read(rdpContext* context, const char* prompt, char* buf,
size_t bufsiz, int from_stdin);
FREERDP_API const char* freerdp_passphrase_read(rdpContext* context, const char* prompt,
char* buf, size_t bufsiz, int from_stdin);
#ifdef __cplusplus
}

View File

@ -30,8 +30,10 @@ extern "C"
{
#endif
FREERDP_API char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size);
FREERDP_API char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size);
FREERDP_API const char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer,
size_t size);
FREERDP_API const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer,
size_t size);
#ifdef __cplusplus
}

View File

@ -75,7 +75,7 @@ UINT32 audio_format_compute_time_length(const AUDIO_FORMAT* format, size_t size)
return mstime;
}
char* audio_format_get_tag_string(UINT16 wFormatTag)
const char* audio_format_get_tag_string(UINT16 wFormatTag)
{
switch (wFormatTag)
{

View File

@ -1948,7 +1948,7 @@ BOOL freerdp_device_equal(const RDPDR_DEVICE* what, const RDPDR_DEVICE* expect)
return TRUE;
}
char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer, size_t length)
const char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer, size_t length)
{
const UINT32 mask =
RAIL_LEVEL_SUPPORTED | RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED |

View File

@ -49,6 +49,7 @@ FREERDP_LOCAL BOOL freerdp_certificate_read_server_cert(rdpCertificate* certific
FREERDP_LOCAL SSIZE_T freerdp_certificate_write_server_cert(const rdpCertificate* certificate,
UINT32 dwVersion, wStream* s);
WINPR_ATTR_MALLOC(freerdp_certificate_free, 1)
FREERDP_LOCAL rdpCertificate* freerdp_certificate_clone(const rdpCertificate* certificate);
FREERDP_LOCAL const rdpCertInfo* freerdp_certificate_get_info(const rdpCertificate* certificate);

View File

@ -384,7 +384,7 @@ const char* freerdp_http_status_string(long status)
}
}
char* freerdp_http_status_string_format(long status, char* buffer, size_t size)
const char* freerdp_http_status_string_format(long status, char* buffer, size_t size)
{
const char* code = freerdp_http_status_string(status);
(void)_snprintf(buffer, size, "%s [%ld]", code, status);

View File

@ -213,7 +213,7 @@ error:
}
}
static char* freerdp_passphrase_read_askpass(const char* prompt, char* buf, size_t bufsiz,
static const char* freerdp_passphrase_read_askpass(const char* prompt, char* buf, size_t bufsiz,
char const* askpass_env)
{
char command[4096] = { 0 };
@ -234,8 +234,8 @@ static char* freerdp_passphrase_read_askpass(const char* prompt, char* buf, size
return buf;
}
char* freerdp_passphrase_read(rdpContext* context, const char* prompt, char* buf, size_t bufsiz,
int from_stdin)
const char* freerdp_passphrase_read(rdpContext* context, const char* prompt, char* buf,
size_t bufsiz, int from_stdin)
{
const char* askpass_env = getenv("FREERDP_ASKPASS");

View File

@ -22,7 +22,7 @@
#include <freerdp/utils/string.h>
#include <freerdp/settings.h>
char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size)
const char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size)
{
struct map_t
{
@ -60,7 +60,7 @@ char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, size_t size)
return buffer;
}
char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size)
const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, size_t size)
{
const UINT32 version = (flags & ServerSessionRedirectionVersionMask) >> 2;
if (flags & REDIRECTION_SUPPORTED)