Add null check 32/142032/2
authorSeungha Son <seungha.son@samsung.com>
Wed, 2 Aug 2017 08:41:17 +0000 (17:41 +0900)
committerSon seungha <seungha.son@samsung.com>
Thu, 3 Aug 2017 08:38:24 +0000 (08:38 +0000)
Signed-off-by: Seungha Son <seungha.son@samsung.com>
Change-Id: I76149b658e6cd20aef116c5d074c17a43d05b819

src/queue.c

index 61220c8..a03ed07 100644 (file)
@@ -101,6 +101,11 @@ int _push_queue(uid_t target_uid, uid_t caller_uid, const char *req_id,
        }
 
        job = calloc(1, sizeof(struct backend_job));
+       if (job == NULL) {
+               ERR("Out of memory");
+               return -1;
+       }
+
        job->target_uid = target_uid;
        job->caller_uid = caller_uid;
        if (req_id)
@@ -132,10 +137,21 @@ static int __init_backends(const char *fpath, const struct stat *sb,
                return 0;
 
        queue = calloc(1, sizeof(struct backend_queue));
+       if (queue == NULL) {
+               ERR("Out of memory");
+               return -1;
+       }
+
        if (typeflag == FTW_F) {
                queue->path = strdup(fpath);
        } else if (typeflag == FTW_SL) {
                queue->path = malloc(sb->st_size + 1);
+               if (queue->path == NULL) {
+                       ERR("Out of memory");
+                       free(queue);
+                       return -1;
+               }
+
                r = readlink(fpath, queue->path, sb->st_size + 1);
                if (r < 0 || r > sb->st_size) {
                        ERR("failed to readlink for %s", fpath);