Skip to content

Commit 7f121b3

Browse files
author
roman
committed
messages server BUGFIX fix new notif memory leak
1 parent ecd2575 commit 7f121b3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/messages_server.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ nc_server_reply_free(struct nc_server_reply *reply)
766766
API struct nc_server_notif *
767767
nc_server_notif_new(struct lyd_node *event, char *eventtime, NC_PARAMTYPE paramtype)
768768
{
769-
struct nc_server_notif *ntf;
769+
struct nc_server_notif *ntf = NULL;
770770
struct lyd_node *elem;
771771
int found;
772772

@@ -791,9 +791,10 @@ nc_server_notif_new(struct lyd_node *event, char *eventtime, NC_PARAMTYPE paramt
791791

792792
if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
793793
ntf->eventtime = strdup(eventtime);
794+
NC_CHECK_ERRMEM_GOTO(!ntf->eventtime, , error);
795+
794796
if (lyd_dup_single(event, NULL, LYD_DUP_RECURSIVE, &ntf->ntf)) {
795-
free(ntf);
796-
return NULL;
797+
goto error;
797798
}
798799
} else {
799800
ntf->eventtime = eventtime;
@@ -802,6 +803,11 @@ nc_server_notif_new(struct lyd_node *event, char *eventtime, NC_PARAMTYPE paramt
802803
ntf->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
803804

804805
return ntf;
806+
807+
error:
808+
free(ntf->eventtime);
809+
free(ntf);
810+
return NULL;
805811
}
806812

807813
API void

0 commit comments

Comments
 (0)