summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-pppoe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd-network/sd-pppoe.c')
-rw-r--r--src/libsystemd-network/sd-pppoe.c38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/libsystemd-network/sd-pppoe.c b/src/libsystemd-network/sd-pppoe.c
index ff064f563f..c6c9da812b 100644
--- a/src/libsystemd-network/sd-pppoe.c
+++ b/src/libsystemd-network/sd-pppoe.c
@@ -36,7 +36,6 @@
#include "random-util.h"
#include "socket-util.h"
#include "async.h"
-#include "refcnt.h"
#include "utf8.h"
#define PPPOE_MAX_PACKET_SIZE 1484
@@ -68,7 +67,7 @@ typedef struct PPPoETags {
} PPPoETags;
struct sd_pppoe {
- RefCount n_ref;
+ unsigned n_ref;
PPPoEState state;
uint64_t host_uniq;
@@ -202,23 +201,34 @@ int sd_pppoe_detach_event(sd_pppoe *ppp) {
}
sd_pppoe *sd_pppoe_ref(sd_pppoe *ppp) {
- if (ppp)
- assert_se(REFCNT_INC(ppp->n_ref) >= 2);
+
+ if (!ppp)
+ return NULL;
+
+ assert(ppp->n_ref > 0);
+ ppp->n_ref++;
return ppp;
}
sd_pppoe *sd_pppoe_unref(sd_pppoe *ppp) {
- if (ppp && REFCNT_DEC(ppp->n_ref) <= 0) {
- pppoe_tags_clear(&ppp->tags);
- free(ppp->ifname);
- free(ppp->service_name);
- sd_pppoe_stop(ppp);
- sd_pppoe_detach_event(ppp);
-
- free(ppp);
- }
+ if (!ppp)
+ return NULL;
+
+ assert(ppp->n_ref > 0);
+ ppp->n_ref--;
+
+ if (ppp->n_ref > 0)
+ return NULL;
+
+ pppoe_tags_clear(&ppp->tags);
+ free(ppp->ifname);
+ free(ppp->service_name);
+ sd_pppoe_stop(ppp);
+ sd_pppoe_detach_event(ppp);
+
+ free(ppp);
return NULL;
}
@@ -231,7 +241,7 @@ int sd_pppoe_new (sd_pppoe **ret) {
if (!ppp)
return -ENOMEM;
- ppp->n_ref = REFCNT_INIT;
+ ppp->n_ref = 1;
ppp->state = _PPPOE_STATE_INVALID;
ppp->ifindex = -1;
ppp->fd = -1;