]> git.proxmox.com Git - mirror_lxcfs.git/commit - bindings.c
bindings: avoid allocating an unused buffer
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 5 Feb 2016 10:52:23 +0000 (11:52 +0100)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 8 Feb 2016 17:15:00 +0000 (09:15 -0800)
commitf366da6554a1b21aec13f0ea9dcfc5aa9936c27a
tree36cb3c1aa8f63339d7e581d53187682d90b5e747
parentbbfd0e331d43ede344f0f6b630ff6961a8c1ec90
bindings: avoid allocating an unused buffer

cgfs_list_children() and cgfs_list_keys() follow the same
pattern with the differences being that one lists
directories, the other files, and that cgfs_list_children()
always allocates an empty list while cgfs_list_keys()
NULL-initializes the list.
Both have a case which returns an error after a list has
been allocated, and in both cases the cleanup code is
guarded with an if(list).
In both cases on success the caller assumes the list is
non-empty which is why cgfs_list_children() returned a list
with a terminating NULL-entry.

This deduplicates the iteration code into a function with a
flag for whether regular files or directories are of
interest and a callback to create the list element.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
bindings.c