Whamcloud - gitweb
libss: fix potential memory leak on realloc() failure
authorTheodore Ts'o <tytso@mit.edu>
Tue, 7 Jan 2014 03:20:38 +0000 (22:20 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 7 Jan 2014 03:54:12 +0000 (22:54 -0500)
Commit 191a03ac5f was an incorrect fix for this issue.  Fix it up.

Addresses-Coverity-ID: #295143
Addresses-Coverity-ID: #1148451

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ss/invocation.c

index 924427a..457e7a2 100644 (file)
@@ -28,7 +28,7 @@ int ss_create_invocation(const char *subsystem_name, const char *version_string,
 {
        register int sci_idx;
        register ss_data *new_table;
-       register ss_data **table, **rt;
+       register ss_data **table;
 
        *code_ptr = 0;
        table = _ss_table;
@@ -42,10 +42,11 @@ int ss_create_invocation(const char *subsystem_name, const char *version_string,
 
        for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
                ;
-       rt = (ss_data **) realloc((char *)table, ((unsigned)sci_idx+2)*size);
-       if (rt == NULL) {
+       table = (ss_data **) realloc((char *)table,
+                                    ((unsigned)sci_idx+2)*size);
+       if (table == NULL) {
                *code_ptr = ENOMEM;
-               free(table);
+               free(new_table);
                return 0;
        }
        table[sci_idx+1] = (ss_data *) NULL;