Skip to content

Commit f40fcbe

Browse files
committed
Introduce strophe_free_and_null()
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
1 parent 13d0354 commit f40fcbe

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ void *strophe_realloc(const xmpp_ctx_t *ctx, void *p, size_t size);
9393
char *strophe_strdup(const xmpp_ctx_t *ctx, const char *s);
9494
char *strophe_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len);
9595
void strophe_free(const xmpp_ctx_t *ctx, void *p);
96+
#define strophe_free_and_null(ctx, p) \
97+
do { \
98+
if (p) { \
99+
strophe_free(ctx, (p)); \
100+
(p) = NULL; \
101+
} \
102+
} while (0)
96103

97104
/* wrappers for xmpp_log at specific levels */
98105
void strophe_error(const xmpp_ctx_t *ctx,

src/conn.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,21 +1804,13 @@ static void _conn_reset(xmpp_conn_t *conn)
18041804

18051805
if (conn->stream_error) {
18061806
xmpp_stanza_release(conn->stream_error->stanza);
1807-
if (conn->stream_error->text)
1808-
strophe_free(ctx, conn->stream_error->text);
1809-
strophe_free(ctx, conn->stream_error);
1810-
conn->stream_error = NULL;
1807+
strophe_free_and_null(ctx, conn->stream_error->text);
1808+
strophe_free_and_null(ctx, conn->stream_error);
18111809
}
18121810

1813-
if (conn->domain)
1814-
strophe_free(ctx, conn->domain);
1815-
if (conn->bound_jid)
1816-
strophe_free(ctx, conn->bound_jid);
1817-
if (conn->stream_id)
1818-
strophe_free(ctx, conn->stream_id);
1819-
conn->domain = NULL;
1820-
conn->bound_jid = NULL;
1821-
conn->stream_id = NULL;
1811+
strophe_free_and_null(ctx, conn->domain);
1812+
strophe_free_and_null(ctx, conn->bound_jid);
1813+
strophe_free_and_null(ctx, conn->stream_id);
18221814
conn->authenticated = 0;
18231815
conn->secured = 0;
18241816
conn->tls_failed = 0;

0 commit comments

Comments
 (0)