On 06/21/2011 04:23 AM, Hannes Reinecke wrote:
> When the startup mode has been specified in iscsid.conf it
> needs to be kept in sync for both settings, 'node.startup'
> and 'node.conn[0].startup'.
> 
> References: bnc#458142
> 
> Signed-off-by: Hannes Reinecke <h...@suse.de>
> ---
>  usr/idbm.c |   25 ++++++++++++++++++++++++-
>  1 files changed, 24 insertions(+), 1 deletions(-)
> 
> diff --git a/usr/idbm.c b/usr/idbm.c
> index a73b410..1f01535 100644
> --- a/usr/idbm.c
> +++ b/usr/idbm.c
> @@ -598,6 +598,8 @@ void idbm_recinfo_config(recinfo_t *info, FILE *f)
>       char name[NAME_MAXVAL];
>       char value[VALUE_MAXVAL];
>       char *line, *nl, buffer[2048];
> +     char *node_startup_value = NULL;
> +     char *conn_startup_value = NULL;
>       int line_number = 0;
>       int c = 0, i;
>  
> @@ -656,8 +658,29 @@ void idbm_recinfo_config(recinfo_t *info, FILE *f)
>               }
>               *(value+i) = 0;
>  
> -             idbm_rec_update_param(info, name, value, line_number);
> +             if (!strcmp(name, "node.startup")) {
> +                     node_startup_value = strdup(value);
> +             }
> +             if (!strcmp(name, "node.conn[0].startup")) {
> +                     conn_startup_value = strdup(value);
> +             }
> +             (void)idbm_rec_update_param(info, name, value, line_number);
>       } while (line);
> +     /*
> +      * Compat hack:
> +      * Keep node.startup and node.conn[0].startup in sync even
> +      * if only one of those has been specified in the config file.
> +      */
> +     if (node_startup_value && !conn_startup_value) {
> +             (void)idbm_rec_update_param(info, "node.conn[0].startup",
> +                                         node_startup_value, -1);
> +             free(node_startup_value);
> +     }
> +     if (conn_startup_value && !node_startup_value) {
> +             (void)idbm_rec_update_param(info, "node.startup",
> +                                         conn_startup_value, -1);
> +             free(conn_startup_value);
> +     }
>  }

I think this is leaking memory.

If both the conn and node startup are set in the record then we leak.
They are both present in the record by default.

Also I think there is a possible leak if the node or conn startup
strings are present twice. In that case we will leak too. This should
not happen normally.

I made the attached patch and it fixed the leaks.

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

diff --git a/usr/idbm.c b/usr/idbm.c
index 2cb346d..d6b795d 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -659,28 +659,32 @@ void idbm_recinfo_config(recinfo_t *info, FILE *f)
                *(value+i) = 0;
 
                if (!strcmp(name, "node.startup")) {
+                       if (node_startup_value)
+                               free(node_startup_value);
                        node_startup_value = strdup(value);
                }
                if (!strcmp(name, "node.conn[0].startup")) {
+                       if (conn_startup_value)
+                               free(conn_startup_value);
                        conn_startup_value = strdup(value);
                }
-               (void)idbm_rec_update_param(info, name, value, line_number);
+               idbm_rec_update_param(info, name, value, line_number);
        } while (line);
        /*
         * Compat hack:
         * Keep node.startup and node.conn[0].startup in sync even
         * if only one of those has been specified in the config file.
         */
-       if (node_startup_value && !conn_startup_value) {
-               (void)idbm_rec_update_param(info, "node.conn[0].startup",
-                                           node_startup_value, 0);
+       if (node_startup_value && !conn_startup_value)
+               idbm_rec_update_param(info, "node.conn[0].startup",
+                                     node_startup_value, 0);
+       if (conn_startup_value && !node_startup_value)
+               idbm_rec_update_param(info, "node.startup",
+                                     conn_startup_value, 0);
+       if (node_startup_value)
                free(node_startup_value);
-       }
-       if (conn_startup_value && !node_startup_value) {
-               (void)idbm_rec_update_param(info, "node.startup",
-                                           conn_startup_value, 0);
+       if (conn_startup_value)
                free(conn_startup_value);
-       }
 }
 
 /*

Reply via email to