Browse Source

TT#111150 convert refcounting functions to macros

Convert ssrc_ctx_put() and ssrc_ctx_hold() to macros to aide in
debugging reference leaks. Having them as inline functions hides the
actual location of the refcount changes.

Obsolete ssrc_ctx_get() as returning values from macros is awkward and
it was only used in two locations.

Also fix a function invocation mishap: obj_get_o() should be used
instead of __obj_get() as the latter is an internal macro.

Change-Id: Icc0d63f04b3816632fd120c1c749cafabbbfa331
pull/1252/head
Richard Fuchs 5 years ago
parent
commit
292ba2e72b
4 changed files with 20 additions and 20 deletions
  1. +4
    -2
      daemon/codec.c
  2. +2
    -2
      daemon/control_ng.c
  3. +2
    -1
      daemon/rtcp.c
  4. +12
    -15
      include/ssrc.h

+ 4
- 2
daemon/codec.c View File

@ -1689,7 +1689,8 @@ void codec_add_raw_packet(struct media_packet *mp) {
p->s = mp->raw;
p->free_func = NULL;
if (mp->rtp && mp->ssrc_out) {
p->ssrc_out = ssrc_ctx_get(mp->ssrc_out);
ssrc_ctx_hold(mp->ssrc_out);
p->ssrc_out = mp->ssrc_out;
p->rtp = mp->rtp;
}
g_queue_push_tail(&mp->packets_out, p);
@ -1882,7 +1883,8 @@ static void __output_rtp(struct media_packet *mp, struct codec_ssrc_handler *ch,
p->ttq_entry.source = handler;
p->rtp = rh;
p->ts = ts;
p->ssrc_out = ssrc_ctx_get(ssrc_out);
ssrc_ctx_hold(ssrc_out);
p->ssrc_out = ssrc_out;
// this packet is dynamically allocated, so we're able to schedule it.
// determine scheduled time to send


+ 2
- 2
daemon/control_ng.c View File

@ -142,7 +142,7 @@ static void __ng_buffer_free(void *p) {
struct ng_buffer *ngbuf = p;
bencode_buffer_free(&ngbuf->buffer);
if (ngbuf->ref)
__obj_put(ngbuf->ref);
obj_put_o(ngbuf->ref);
}
int control_ng_process(str *buf, const endpoint_t *sin, char *addr,
@ -170,7 +170,7 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr,
mutex_init(&ngbuf->lock);
mutex_lock(&ngbuf->lock);
if (ref)
ngbuf->ref = __obj_get(ref); // hold until we're done
ngbuf->ref = obj_get_o(ref); // hold until we're done
int ret = bencode_buffer_init(&ngbuf->buffer);
assert(ret == 0);


+ 2
- 1
daemon/rtcp.c View File

@ -1543,7 +1543,8 @@ void rtcp_receiver_reports(GQueue *out, struct ssrc_hash *hash, struct call_mono
if (!atomic64_get(&i->packets))
continue;
g_queue_push_tail(out, ssrc_ctx_get(i));
ssrc_ctx_hold(i);
g_queue_push_tail(out, i);
}
rwlock_unlock_r(&hash->lock);
}


+ 12
- 15
include/ssrc.h View File

@ -213,21 +213,18 @@ void payload_tracker_init(struct payload_tracker *t);
void payload_tracker_add(struct payload_tracker *, int);
INLINE void ssrc_ctx_put(struct ssrc_ctx **c) {
if (!c || !*c)
return;
obj_put(&(*c)->parent->h);
*c = NULL;
}
INLINE struct ssrc_ctx *ssrc_ctx_get(struct ssrc_ctx *c) {
if (!c)
return NULL;
obj_hold(&c->parent->h);
return c;
}
INLINE void ssrc_ctx_hold(struct ssrc_ctx *c) {
ssrc_ctx_get(c);
}
#define ssrc_ctx_put(c) \
do { \
if ((c) && *(c)) { \
obj_put(&(*c)->parent->h); \
*(c) = NULL; \
} \
} while (0)
#define ssrc_ctx_hold(c) \
do { \
if ((c)) \
obj_hold(&(c)->parent->h); \
} while (0)


Loading…
Cancel
Save