diff options
author | Magnus Vigerlöf <Magnus.Vigerlof@home.se> | 2007-04-10 23:55:36 +0300 |
---|---|---|
committer | Daniel Stone <daniels@endtroducing.fooishbar.org> | 2007-04-10 23:58:20 +0300 |
commit | 20674dcbb2373a0af287883bc008fb6fb23d4466 (patch) | |
tree | cd99ca665d83ec565622bde714c385edba1779c3 /config | |
parent | 82962bbae2b4fda274625d1712ef839ce1ab9dc8 (diff) |
Config: Fix memory leaks
Fix memory leaks that could occur along the error path.
Diffstat (limited to 'config')
-rw-r--r-- | config/config.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/config/config.c b/config/config.c index b8d24289b..aae5c6e4d 100644 --- a/config/config.c +++ b/config/config.c @@ -110,6 +110,11 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error) options->key = xstrdup("_source"); options->value = xstrdup("client/dbus"); + if(!options->key || !options->value) { + ErrorF("[config] couldn't allocate first key/value pair\n"); + ret = BadAlloc; + goto unwind; + } while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY) { tmpo = (InputOption *) xcalloc(sizeof(InputOption), 1); @@ -118,6 +123,8 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error) ret = BadAlloc; goto unwind; } + tmpo->next = options; + options = tmpo; dbus_message_iter_recurse(iter, &subiter); @@ -132,8 +139,8 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error) tmp); MALFORMED_MESSAGE(); } - tmpo->key = xstrdup(tmp); - if (!tmpo->key) { + options->key = xstrdup(tmp); + if (!options->key) { ErrorF("[config] couldn't duplicate key!\n"); ret = BadAlloc; goto unwind; @@ -148,15 +155,13 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error) dbus_message_iter_get_basic(&subiter, &tmp); if (!tmp) MALFORMED_MESSAGE(); - tmpo->value = xstrdup(tmp); - if (!tmpo->value) { + options->value = xstrdup(tmp); + if (!options->value) { ErrorF("[config] couldn't duplicate option!\n"); ret = BadAlloc; goto unwind; } - tmpo->next = options; - options = tmpo; dbus_message_iter_next(iter); } @@ -164,16 +169,8 @@ configAddDevice(DBusMessage *message, DBusMessageIter *iter, DBusError *error) if (ret != Success) DebugF("[config] NewInputDeviceRequest failed\n"); - return ret; - + /* Fall through, must deallocate memory we've allocated */ unwind: - if (tmpo->key) - xfree(tmpo->key); - if (tmpo->value) - xfree(tmpo->value); - if (tmpo) - xfree(tmpo); - while (options) { tmpo = options; options = options->next; |