home · contact · privacy
At clean-up, free memory of map object definitions, too.
[plomrogue] / src / wincontrol.c
index 715aebb4d5d856964e12071630c5bd2ffb0bd10c..74c9c2a297d6fc9e0fcca3c1afdd83855cd56e2c 100644 (file)
 
 
 
-extern void free_win(struct Win * win)
-{
-    free(win->_title);
-    free(win);
-}
-
-
-
 extern struct Win * init_win_from_file(struct World * world, char * w_name,
                                        void (* f) (struct Win *))
 {
@@ -43,7 +35,8 @@ extern struct Win * init_win_from_file(struct World * world, char * w_name,
     err = "Trouble in init_win_from_file() with fgets().";
     exit_err(NULL == fgets(line, linemax, file), world, err);
     char * title = malloc(strlen(line));
-    memcpy(title, line, strlen(line) - 1);
+    memcpy(title, line, strlen(line) - 1);   /* Eliminate newline char at end */
+    title[strlen(line) - 1] = '\0';          /* of string.                    */
     exit_err(NULL == fgets(line, linemax, file), world, err);
     int16_t height = atoi(line);
     exit_err(NULL == fgets(line, linemax, file), world, err);
@@ -53,10 +46,10 @@ extern struct Win * init_win_from_file(struct World * world, char * w_name,
     exit_err(fclose(file), world, err);
 
     struct WinMeta * wmeta = world->wins.meta;
-    struct Win * w = malloc(sizeof(struct Win));
-    init_win(wmeta, w, title, height, width, world, f);
+    struct Win * wp; // = malloc(sizeof(struct Win));
+    init_win(wmeta, &wp, title, height, width, world, f);
     free(title);
-    return w;
+    return wp;
 }