]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Reduce creation and fix memory leak of frrscripting pointers
authorDonald Sharp <sharpd@nvidia.com>
Fri, 5 May 2023 15:05:12 +0000 (11:05 -0400)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Tue, 9 May 2023 12:38:58 +0000 (12:38 +0000)
There are two issues being addressed:

a) The ZEBRA_ON_RIB_PROCESS_HOOK_CALL script point
was creating a fs pointer per dplane ctx in
rib_process_dplane_results().

b) The fs pointer was not being deleted and directly
leaked.

For (a) Move the creation of the fs to outside
the do while loop.

For (b) At function end ensure that the pointer
is actually deleted.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit d8be1399720ca36485b6a2209b143679b01b83cb)

zebra/zebra_rib.c

index 08391f1a3dfbbdd64217c4fb187a7a008090e806..171837610ace192b2a6a38dff68549cea8170db6 100644 (file)
@@ -4587,6 +4587,21 @@ static void rib_process_dplane_results(struct thread *thread)
        struct dplane_ctx_q ctxlist;
        bool shut_p = false;
 
+#ifdef HAVE_SCRIPTING
+       char *script_name =
+               frrscript_names_get_script_name(ZEBRA_ON_RIB_PROCESS_HOOK_CALL);
+
+       int ret = 1;
+       struct frrscript *fs = NULL;
+
+       if (script_name) {
+               fs = frrscript_new(script_name);
+               if (fs)
+                       ret = frrscript_load(fs, ZEBRA_ON_RIB_PROCESS_HOOK_CALL,
+                                            NULL);
+       }
+#endif /* HAVE_SCRIPTING */
+
        /* Dequeue a list of completed updates with one lock/unlock cycle */
 
        do {
@@ -4620,24 +4635,7 @@ static void rib_process_dplane_results(struct thread *thread)
                        continue;
                }
 
-#ifdef HAVE_SCRIPTING
-               char *script_name = frrscript_names_get_script_name(
-                       ZEBRA_ON_RIB_PROCESS_HOOK_CALL);
-
-               int ret = 1;
-               struct frrscript *fs;
-
-               if (script_name) {
-                       fs = frrscript_new(script_name);
-                       if (fs)
-                               ret = frrscript_load(
-                                       fs, ZEBRA_ON_RIB_PROCESS_HOOK_CALL,
-                                       NULL);
-               }
-#endif /* HAVE_SCRIPTING */
-
                while (ctx) {
-
 #ifdef HAVE_SCRIPTING
                        if (ret == 0)
                                frrscript_call(fs,
@@ -4747,6 +4745,11 @@ static void rib_process_dplane_results(struct thread *thread)
                }
 
        } while (1);
+
+#ifdef HAVE_SCRIPTING
+       if (fs)
+               frrscript_delete(fs);
+#endif
 }
 
 /*