Fix: check reference counts for overflow
[lttng-modules.git] / lttng-events.c
index 1f34fbbc3341afd6ce8094c02fba4ed4b818bb70..f0f5d0f80dbe340bf1e4663681ff621acd25f504 100644 (file)
@@ -1085,17 +1085,22 @@ int lttng_session_list_tracker_pids(struct lttng_session *session)
                ret = PTR_ERR(tracker_pids_list_file);
                goto file_error;
        }
+       if (atomic_long_add_unless(&session->file->f_count,
+               1, INT_MAX) == INT_MAX) {
+               goto refcount_error;
+       }
        ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file);
        if (ret < 0)
                goto open_error;
        m = tracker_pids_list_file->private_data;
        m->private = session;
        fd_install(file_fd, tracker_pids_list_file);
-       atomic_long_inc(&session->file->f_count);
 
        return file_fd;
 
 open_error:
+       atomic_long_dec(&session->file->f_count);
+refcount_error:
        fput(tracker_pids_list_file);
 file_error:
        put_unused_fd(file_fd);
This page took 0.022928 seconds and 4 git commands to generate.