uwac: change seat API to not reference disposed UwacSeat
authorDavid Fort <contact@hardening-consulting.com>
Thu, 25 Oct 2018 13:20:18 +0000 (15:20 +0200)
committerDavid Fort <contact@hardening-consulting.com>
Thu, 25 Oct 2018 13:24:29 +0000 (15:24 +0200)
This is a false positive returned by covscan, but that doesn't hurt to fix it.

uwac/include/uwac/uwac.h
uwac/libuwac/uwac-display.c
uwac/libuwac/uwac-input.c

index 5042803..6a85bc7 100644 (file)
@@ -37,6 +37,7 @@ typedef struct uwac_display UwacDisplay;
 typedef struct uwac_output UwacOutput;
 typedef struct uwac_window UwacWindow;
 typedef struct uwac_seat UwacSeat;
+typedef uint32_t UwacSeatId;
 
 
 /** @brief error codes */
@@ -111,7 +112,12 @@ struct uwac_new_seat_event {
 };
 typedef struct uwac_new_seat_event UwacSeatNewEvent;
 
-typedef struct uwac_new_seat_event UwacSeatRemovedEvent;
+
+struct uwac_removed_seat_event {
+       int type;
+       UwacSeatId id;
+};
+typedef struct uwac_removed_seat_event UwacSeatRemovedEvent;
 
 struct uwac_keyboard_enter_event {
        int type;
@@ -213,6 +219,7 @@ union uwac_event {
        int type;
        UwacOutputNewEvent output_new;
        UwacSeatNewEvent seat_new;
+       UwacSeatRemovedEvent seat_removed;
        UwacPointerEnterLeaveEvent mouse_enter_leave;
        UwacPointerMotionEvent mouse_motion;
        UwacPointerButtonEvent mouse_button;
@@ -479,6 +486,14 @@ UWAC_API UwacReturnCode UwacNextEvent(UwacDisplay *display, UwacEvent *event);
  */
 UWAC_API const char *UwacSeatGetName(const UwacSeat *seat);
 
+/**
+ * returns the id of the given UwacSeat
+ *
+ * @param seat the UwacSeat
+ * @return the id of the seat
+ */
+UWAC_API UwacSeatId UwacSeatGetId(const UwacSeat *seat);
+
 #ifdef __cplusplus
 }
 #endif
index 677d123..cd2ee52 100644 (file)
@@ -270,7 +270,7 @@ static void registry_handle_global_remove(void* data, struct wl_registry* regist
                        ev = (UwacSeatRemovedEvent*)UwacDisplayNewEvent(d, UWAC_EVENT_REMOVED_SEAT);
 
                        if (ev)
-                               ev->seat = seat;
+                               ev->id = name;
                }
 
                wl_list_remove(&global->link);
index 8daf717..ecb3b1a 100644 (file)
@@ -865,3 +865,7 @@ void UwacSeatDestroy(UwacSeat *s) {
 const char *UwacSeatGetName(const UwacSeat *seat) {
        return seat->name;
 }
+
+UwacSeatId UwacSeatGetId(const UwacSeat *seat) {
+       return seat->seat_id;
+}