wClipboard: improve error handling
authorilammy <a.lozovsky@gmail.com>
Sat, 8 Apr 2017 23:29:50 +0000 (02:29 +0300)
committerilammy <a.lozovsky@gmail.com>
Sun, 9 Apr 2017 00:15:48 +0000 (03:15 +0300)
commit228916bcec8f501c3086cede59e45cfbce6d7af9
tree82c29205dfc1a8bcbf0fea3113048d9475e4661e
parenta992743d993f3ea2627bdbe24b8b538ba9be5dbc
wClipboard: improve error handling

Unify error handling in ClipboardInitFormats() and actually handle the
return value of ClipboardInitSynthesizers(). Currently it always returns
TRUE, but this may change, so we'd better be clean.

Declare 'formatName' in wClipboardFormat as non-const. It is customary
in C to declare owned pointers as non-const because various deallocation
functions like free() take non-const pointers as arguments. Furthermore,
const char* is tightly associated with "string literals" which must not
be freed. Thus declaring this field as non-const is more accurate, and
removes that ugly void* cast from ClipboardInitFormats().

Unify error handling in ClipboardCreate(). The cleanup snippet should
not be repeated as it's prone to errors, like leaking the allocation of
clipboard->formats when ClipboardInitFormats() fails. Unified error
handling makes it much harder to forget resource cleanup on errors.
winpr/libwinpr/clipboard/clipboard.c
winpr/libwinpr/clipboard/clipboard.h