Module: kamailio Branch: master Commit: 75187b6e931b2980811abb7a4ea78ceb21866202 URL: https://github.com/kamailio/kamailio/commit/75187b6e931b2980811abb7a4ea78ceb21866202
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2026-02-08T15:45:40+01:00 core: macros to duplicate/update str in shm - added the update variant, based on former duplicate function --- Modified: src/core/ut.h --- Diff: https://github.com/kamailio/kamailio/commit/75187b6e931b2980811abb7a4ea78ceb21866202.diff Patch: https://github.com/kamailio/kamailio/commit/75187b6e931b2980811abb7a4ea78ceb21866202.patch --- diff --git a/src/core/ut.h b/src/core/ut.h index 1f4c84daecd..eac812cb749 100644 --- a/src/core/ut.h +++ b/src/core/ut.h @@ -871,9 +871,10 @@ static inline str *shm_str_dup_block(const str *src) * The copy will be zero-terminated * \param dst destination * \param src source + * \param mode if 1, free destination buffer if set * \return 0 on success, -1 on failure */ -static inline int shm_str_dup(str *dst, const str *src) +static inline int shm_str_dup_mode(str *dst, const str *src, int mode) { /* NULL checks */ if(dst == NULL || src == NULL) { @@ -897,6 +898,9 @@ static inline int shm_str_dup(str *dst, const str *src) dst->len = src->len; } + if(mode == 1 && dst->s != NULL) { + shm_free(dst->s); + } dst->s = (char *)shm_malloc(dst->len + 1); if(dst->s == NULL) { SHM_MEM_ERROR; @@ -915,6 +919,9 @@ static inline int shm_str_dup(str *dst, const str *src) return 0; } +#define shm_str_dup(dst, src) shm_str_dup_mode(dst, src, 0) +#define shm_str_update(dst, src) shm_str_dup_mode(dst, src, 1) + /** * \brief Make a copy of a char pointer to a char pointer using shm_malloc * \param src source _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
