Fix: check reference counts for overflow
[lttng-modules.git] / lttng-events.c
index 4b76ea03d72c5f7d31aadf975b2667072a07e857..d0ebb2987518fd61b68cd6455602c3a39c8135c6 100644 (file)
@@ -1043,17 +1043,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.022933 seconds and 4 git commands to generate.