[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Correctly initialize modopts in loader (#531932).



Under certain conditions, modopts is never initialized.  This patch
fixes up that while preserving the existing functionality introduced
with 29e18c35.
---
 loader/modules.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/loader/modules.c b/loader/modules.c
index d5129b7..f61f680 100644
--- a/loader/modules.c
+++ b/loader/modules.c
@@ -117,16 +117,18 @@ static void addOption(const char *module, const char *option) {
     }
 
     if (found) {
-        modopts[i].options = realloc(modopts[i].options,
-                                     sizeof(modopts[i].options) *
-                                     (modopts[i].numopts + 1));
-        modopts[i].options[modopts[i].numopts - 1] = strdup(option);
-        modopts[i].options[modopts[i].numopts] = NULL;
-    } else {
-        modopts = realloc(modopts, sizeof(*modopts) * (nummodopts + 1));
-        modopts[nummodopts].name = strdup(module);
-        modopts[nummodopts].numopts = 1;
-        modopts[nummodopts++].options = NULL;
+        if (modopts == NULL) {
+            modopts = realloc(modopts, sizeof(*modopts) * (nummodopts + 1));
+            modopts[nummodopts].name = strdup(module);
+            modopts[nummodopts].numopts = 1;
+            modopts[nummodopts++].options = NULL;
+        } else {
+            modopts[i].options = realloc(modopts[i].options,
+                                         sizeof(modopts[i].options) *
+                                         (modopts[i].numopts + 1));
+            modopts[i].options[modopts[i].numopts - 1] = strdup(option);
+            modopts[i].options[modopts[i].numopts] = NULL;
+        }
     }
 
     return;
-- 
1.6.5.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]