do_noncefile_create: Avoid freeing uninitialized memory on error

We could free all of these without having ever successfully
initialized them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103597
(cherry picked from commit 6d08f5c04e)
This commit is contained in:
Simon McVittie 2017-11-06 19:10:42 +00:00
parent 208af9a447
commit d000891624

View file

@ -280,6 +280,12 @@ do_noncefile_create (DBusNonceFile *noncefile,
_dbus_assert (noncefile);
/* Make it valid to "free" these even if _dbus_string_init() runs
* out of memory: see comment in do_check_nonce() */
_dbus_string_init_const (&randomStr, "");
_dbus_string_init_const (&noncefile->dir, "");
_dbus_string_init_const (&noncefile->path, "");
if (!_dbus_string_init (&randomStr))
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);