If malloc|calloc|strdup function is not succesfull
then ECGOTHER should be returned (not ECGFAIL)

Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
---

 src/api.c |   45 ++++++++++++++++++++++++++++++---------------
 1 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/src/api.c b/src/api.c
index d5cc94f..aab13d9 100644
--- a/src/api.c
+++ b/src/api.c
@@ -723,8 +723,10 @@ int cg_add_duplicate_mount(struct cg_mount_table_s *item, 
const char *path)
        struct cg_mount_point *mount, *it;
 
        mount = malloc(sizeof(struct cg_mount_point));
-       if (!mount)
-               return ECGFAIL;
+       if (!mount) {
+               last_errno = errno;
+               return ECGOTHER;
+       }
        mount->next = NULL;
        strncpy(mount->path, path, sizeof(mount->path));
        mount->path[sizeof(mount->path)-1] = '\0';
@@ -1342,7 +1344,8 @@ static int cgroup_copy_controller_values(struct 
cgroup_controller *dst,
 
                dst->values[i] = calloc(1, sizeof(struct control_value));
                if (!dst->values[i]) {
-                       ret = ECGFAIL;
+                       last_errno = errno;
+                       ret = ECGOTHER;
                        goto err;
                }
 
@@ -1382,7 +1385,8 @@ int cgroup_copy_cgroup(struct cgroup *dst, struct cgroup 
*src)
 
                dst->controller[i] = calloc(1, sizeof(struct 
cgroup_controller));
                if (!dst->controller[i]) {
-                       ret = ECGFAIL;
+                       last_errno = errno;
+                       ret = ECGOTHER;
                        goto err;
                }
 
@@ -1546,7 +1550,8 @@ static int cgroup_get_parent_name(struct cgroup *cgroup, 
char **parent)
 
        dir = strdup(cgroup->name);
        if (!dir) {
-               return ECGFAIL;
+               last_errno = errno;
+               return ECGOTHER;
        }
        cgroup_dbg("group name is %s\n", dir);
 
@@ -1561,8 +1566,10 @@ static int cgroup_get_parent_name(struct cgroup *cgroup, 
char **parent)
        }
        else {
                *parent = strdup(pdir);
-               if (*parent == NULL)
-                       ret = ECGFAIL;
+               if (*parent == NULL) {
+                       last_errno = errno;
+                       ret = ECGOTHER;
+               }
        }
        free(dir);
 
@@ -1921,8 +1928,10 @@ int cgroup_delete_cgroup_ext(struct cgroup *cgroup, int 
flags)
                         * it afterwards.
                         */
                        parent_name = strdup(".");
-                       if (parent_name == NULL)
-                               return ECGFAIL;
+                       if (parent_name == NULL) {
+                               last_errno = errno;
+                               return ECGOTHER;
+                       }
                        delete_group = 0;
                } else
                        /*
@@ -3832,8 +3841,10 @@ int cgroup_dictionary_create(struct cgroup_dictionary 
**dict,
        *dict = (struct cgroup_dictionary *) calloc(
                        1, sizeof(struct cgroup_dictionary));
 
-       if (!dict)
-               return ECGFAIL;
+       if (!dict) {
+               last_errno = errno;
+               return ECGOTHER;
+       }
        (*dict)->flags = flags;
        return 0;
 }
@@ -3849,8 +3860,10 @@ int cgroup_dictionary_add(struct cgroup_dictionary *dict,
 
        it = (struct cgroup_dictionary_item *) malloc(
                        sizeof(struct cgroup_dictionary_item));
-       if (!it)
-               return ECGFAIL;
+       if (!it) {
+               last_errno = errno;
+               return ECGOTHER;
+       }
 
        it->next = NULL;
        it->name = name;
@@ -3901,8 +3914,10 @@ int cgroup_dictionary_iterator_begin(struct 
cgroup_dictionary *dict,
 
        iter = (struct cgroup_dictionary_iterator *) malloc(
                        sizeof(struct cgroup_dictionary_iterator));
-       if (!iter)
-               return ECGFAIL;
+       if (!iter) {
+               last_errno = errno;
+               return ECGOTHER;
+       }
 
        iter->item = dict->head;
        *handle = iter;


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to