From 0572572eb9fefb6fe18a0562e4fe8cbe6c12d9f2 Mon Sep 17 00:00:00 2001 From: Norbert Federa Date: Fri, 19 Oct 2018 11:30:01 +0200 Subject: [PATCH] fix issue with fnObjectFree and related casts - remove unnecessary/dangerous OBJECT_xxx function-style casts - fix -Wstrict-prototypes issue with OBJECT_NEW_FN definition --- channels/drive/client/drive_main.c | 10 ++++++- channels/rdpdr/client/devman.c | 7 +++-- libfreerdp/codec/rfx.c | 29 +++++++++++-------- winpr/include/winpr/collections.h | 4 +-- winpr/libwinpr/utils/collections/ObjectPool.c | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index d6bfd6dd2..df361c0b1 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -864,6 +864,14 @@ static UINT drive_free(DEVICE* device) return drive_free_int(drive); } +/** + * Helper function used for freeing list dictionary value object + */ +static void drive_file_objfree(void* obj) +{ + drive_file_free((DRIVE_FILE*) obj); +} + /** * Function description * @@ -925,7 +933,7 @@ static UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, goto out_error; } - ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free; + ListDictionary_ValueObject(drive->files)->fnObjectFree = drive_file_objfree; drive->IrpQueue = MessageQueue_New(NULL); if (!drive->IrpQueue) diff --git a/channels/rdpdr/client/devman.c b/channels/rdpdr/client/devman.c index 3f5dd153a..93db1b70b 100644 --- a/channels/rdpdr/client/devman.c +++ b/channels/rdpdr/client/devman.c @@ -41,8 +41,10 @@ #include "devman.h" -void devman_device_free(DEVICE* device) +static void devman_device_free(void* obj) { + DEVICE* device = (DEVICE*) obj; + if (!device) return; @@ -75,8 +77,7 @@ DEVMAN* devman_new(rdpdrPlugin* rdpdr) return NULL; } - ListDictionary_ValueObject(devman->devices)->fnObjectFree = - (OBJECT_FREE_FN) devman_device_free; + ListDictionary_ValueObject(devman->devices)->fnObjectFree = devman_device_free; return devman; } diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index b7b08738d..d54b8a3d6 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -145,8 +145,9 @@ static void rfx_profiler_print(RFX_CONTEXT* context) PROFILER_PRINT_FOOTER } -static void rfx_tile_init(RFX_TILE* tile) +static void rfx_tile_init(void* obj) { + RFX_TILE* tile = (RFX_TILE*)obj; if (tile) { tile->x = 0; @@ -160,9 +161,10 @@ static void rfx_tile_init(RFX_TILE* tile) } } -static RFX_TILE* rfx_decoder_tile_new(void) +static void* rfx_decoder_tile_new(void* val) { RFX_TILE* tile = NULL; + WINPR_UNUSED(val); if (!(tile = (RFX_TILE*) calloc(1, sizeof(RFX_TILE)))) return NULL; @@ -177,8 +179,10 @@ static RFX_TILE* rfx_decoder_tile_new(void) return tile; } -static void rfx_decoder_tile_free(RFX_TILE* tile) +static void rfx_decoder_tile_free(void* obj) { + RFX_TILE* tile = (RFX_TILE*)obj; + if (tile) { if (tile->allocated) @@ -188,14 +192,15 @@ static void rfx_decoder_tile_free(RFX_TILE* tile) } } -static RFX_TILE* rfx_encoder_tile_new(void) +static void* rfx_encoder_tile_new(void* val) { - return (RFX_TILE*)calloc(1, sizeof(RFX_TILE)); + WINPR_UNUSED(val); + return calloc(1, sizeof(RFX_TILE)); } -static void rfx_encoder_tile_free(RFX_TILE* tile) +static void rfx_encoder_tile_free(void* obj) { - free(tile); + free(obj); } RFX_CONTEXT* rfx_context_new(BOOL encoder) @@ -231,17 +236,17 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) goto error_tilePool; pool = ObjectPool_Object(priv->TilePool); - pool->fnObjectInit = (OBJECT_INIT_FN) rfx_tile_init; + pool->fnObjectInit = rfx_tile_init; if (context->encoder) { - pool->fnObjectNew = (OBJECT_NEW_FN) rfx_encoder_tile_new; - pool->fnObjectFree = (OBJECT_FREE_FN) rfx_encoder_tile_free; + pool->fnObjectNew = rfx_encoder_tile_new; + pool->fnObjectFree = rfx_encoder_tile_free; } else { - pool->fnObjectNew = (OBJECT_NEW_FN) rfx_decoder_tile_new; - pool->fnObjectFree = (OBJECT_FREE_FN) rfx_decoder_tile_free; + pool->fnObjectNew = rfx_decoder_tile_new; + pool->fnObjectFree = rfx_decoder_tile_free; } /* diff --git a/winpr/include/winpr/collections.h b/winpr/include/winpr/collections.h index 237e5b348..2f47c483c 100644 --- a/winpr/include/winpr/collections.h +++ b/winpr/include/winpr/collections.h @@ -35,9 +35,7 @@ extern "C" { #endif -/* We don't know if the new function will require an argument. - * Leave the braces empty, C defines that as variable arguments. */ -typedef void* (*OBJECT_NEW_FN)(); +typedef void* (*OBJECT_NEW_FN)(void* val); typedef void (*OBJECT_INIT_FN)(void* obj); typedef void (*OBJECT_UNINIT_FN)(void* obj); typedef void (*OBJECT_FREE_FN)(void* obj); diff --git a/winpr/libwinpr/utils/collections/ObjectPool.c b/winpr/libwinpr/utils/collections/ObjectPool.c index 3eb573687..293298a48 100644 --- a/winpr/libwinpr/utils/collections/ObjectPool.c +++ b/winpr/libwinpr/utils/collections/ObjectPool.c @@ -51,7 +51,7 @@ void* ObjectPool_Take(wObjectPool* pool) if (!obj) { if (pool->object.fnObjectNew) - obj = pool->object.fnObjectNew(); + obj = pool->object.fnObjectNew(NULL); } if (pool->object.fnObjectInit)