]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Allow memory to be cleaned up for error cases in ptm
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 4 Dec 2017 23:59:47 +0000 (18:59 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 4 Dec 2017 23:59:47 +0000 (18:59 -0500)
ptm_lib.c had no way to cleanup after itself when an
error was detected.  This adds a function to cleanup
context in such a case.

A followup commit will use this new functionality.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/ptm_lib.c
lib/ptm_lib.h

index e881d49225e48a8f8beeb1513ef6cfb3d079080e..28d26149e5d39afc6f3107c67d8a49d0d4333266 100644 (file)
@@ -223,6 +223,25 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt,
        return 0;
 }
 
+int ptm_lib_cleanup_msg(ptm_lib_handle_t *hdl, void *ctxt)
+{
+       ptm_lib_msg_ctxt_t *p_ctxt = ctxt;
+       csv_t *csv;
+
+       if (!p_ctxt) {
+               ERRLOG("%s: no context \n", __FUNCTION__);
+               return -1;
+       }
+
+       csv = p_ctxt->csv;
+
+       csv_clean(csv);
+       csv_free(csv);
+       free(p_ctxt);
+
+       return 0;
+}
+
 int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len)
 {
        ptm_lib_msg_ctxt_t *p_ctxt = ctxt;
index bc8fe4ac54d3f1ad7c52130d7673c0f7e8aaefa4..fc4d520dcb41b4c188d9340c7ee5a5edf96cc67b 100644 (file)
@@ -63,5 +63,6 @@ int ptm_lib_find_key_in_msg(void *, const char *, char *);
 int ptm_lib_init_msg(ptm_lib_handle_t *, int, int, void *, void **);
 int ptm_lib_append_msg(ptm_lib_handle_t *, void *, const char *, const char *);
 int ptm_lib_complete_msg(ptm_lib_handle_t *, void *, char *, int *);
+int ptm_lib_cleanup_msg(ptm_lib_handle_t *, void *);
 
 #endif