Project

General

Profile

Actions

Bug #6393

open

osmo_io conflating osmo_iofd_unregister vs osmo_iofd_close

Added by laforge 2 months ago. Updated 2 months ago.

Status:
New
Priority:
Normal
Assignee:
Category:
libosmocore
Target version:
-
Start date:
03/07/2024
Due date:
% Done:

0%

Spec Reference:

Description

I've been starting to work on something like an osmo_io API user manual, and as part of that tried to think about how to guard osmo_io against invalid usage.

We have
  • osmo_iofd_unregister
  • osmo_iofd_close
  • osmo_iofd_free
Oddities:
  • osmo_iofd_unregister sets the IOFD_FLAG_CLOSED flag, even though it does not close
    • osmo_iofd_register clears the IOFD_FLAG_CLOSED, so there's some symmetry, despite the name
  • osmo_iofd_close also sets the IOFD_FLAG_CLOSED flag, but without unregistering
    • this mean we cannot use the IOFD_FLAG_CLOSED to check in osmo_iofd_unregister if the iofd was already unregistered
    • it actually doesn't close the fd unless there is an osmo_iofd_ops.close call-back from the backend
    • however, it does always set iofd->fd to -1, so if no such call-back exists, we have a fd leak
  • osmo_iofd_free calls osmo_iofd_close, but not osmo_iofd_unregister. So it somehow tries to do whatever is needed before the free, but only half of it.

I'm not entirely sure yet how to untangle this. Maybe we need multiple flags to properly distinguish the closed from the unregistered state? Or maybe we don't need another flag and use iofd->fd == -1 to determine the actual closed status, and rename the CLOSED flag to n UNREGISTERED flag?

Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)