free the memory we allocate to the child name
[tridge/dbench.git] / child.c
diff --git a/child.c b/child.c
index e6b4845ad395a75ce9a5512bd59ba3bc4aa53562..32f9e42456ecd290acb8e43f97a1760dfc4039bd 100644 (file)
--- a/child.c
+++ b/child.c
@@ -116,9 +116,9 @@ static void child_op(struct child_struct *child, const char *opname,
                return;
        }
 
-       for (i=0;nb_ops.ops[i].name;i++) {
-               if (strcasecmp(op.op, nb_ops.ops[i].name) == 0) {
-                       nb_ops.ops[i].fn(&op);
+       for (i=0;nb_ops->ops[i].name;i++) {
+               if (strcasecmp(op.op, nb_ops->ops[i].name) == 0) {
+                       nb_ops->ops[i].fn(&op);
                        finish_op(child, &child->ops[i]);
                        return;
                }
@@ -130,10 +130,11 @@ static void child_op(struct child_struct *child, const char *opname,
 
 
 /* run a test that simulates an approximate netbench client load */
+#define MAX_PARM_LEN 1024
 void child_run(struct child_struct *child0, const char *loadfile)
 {
        int i;
-       char line[1024], fname[1024], fname2[1024];
+       char line[MAX_PARM_LEN], fname[MAX_PARM_LEN], fname2[MAX_PARM_LEN];
        char **sparams, **params;
        char *p;
        const char *status;
@@ -142,6 +143,12 @@ void child_run(struct child_struct *child0, const char *loadfile)
        double targett;
        struct child_struct *child;
 
+       f = fopen(loadfile, "r");
+       if (f == NULL) {
+               perror(loadfile);
+               exit(1);
+       }
+
        for (child=child0;child<child0+options.clients_per_process;child++) {
                child->line = 0;
                asprintf(&child->cname,"client%d", child->id);
@@ -149,13 +156,8 @@ void child_run(struct child_struct *child0, const char *loadfile)
 
        sparams = calloc(20, sizeof(char *));
        for (i=0;i<20;i++) {
-               sparams[i] = malloc(100);
-       }
-
-       f = fopen(loadfile, "r");
-       if (f == NULL) {
-               perror(loadfile);
-               exit(1);
+               sparams[i] = malloc(MAX_PARM_LEN);
+               memset(sparams[i], 0, MAX_PARM_LEN);
        }
 
 again:
@@ -203,7 +205,8 @@ again:
                }
 
                if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
-                   strncmp(params[i-1], "0x", 2) != 0) {
+                   strncmp(params[i-1], "0x", 2) != 0 &&
+                   strncmp(params[i-1], "*", 1) != 0) {
                        printf("Badly formed status at line %d\n", child->line);
                        continue;
                }
@@ -236,6 +239,10 @@ again:
                }
        }
 
+       if (options.run_once) {
+               goto done;
+       }
+
        rewind(f);
        goto again;
 
@@ -245,8 +252,12 @@ done:
                child->cleanup = 1;
                fflush(stdout);
                if (!options.skip_cleanup) {
-                       nb_ops.cleanup(child);
+                       nb_ops->cleanup(child);
                }
                child->cleanup_finished = 1;
+               if(child->cname){
+                       free(child->cname);
+                       child->cname = NULL;
+               }
        }
 }