libdvbv5/dvb-file: fix allocation of dvb_file
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 17 Nov 2013 21:31:55 +0000 (19:31 -0200)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 27 Nov 2013 11:24:40 +0000 (09:24 -0200)
Correct a few allocation issues reported by Valgrind:

- Size of dvb_file is wrong;
- getline requires a free after end using it;
- entries should be freed at dvb_file_free().

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/include/dvb-file.h
lib/libdvbv5/dvb-file.c

index cdbd18c..87beb48 100644 (file)
@@ -90,22 +90,23 @@ static inline void dvb_file_free(struct dvb_file *dvb_file)
        while (entry) {
                next = entry->next;
                if (entry->channel)
-                       free (entry->channel);
+                       free(entry->channel);
                if (entry->vchannel)
-                       free (entry->vchannel);
+                       free(entry->vchannel);
                if (entry->location)
-                       free (entry->location);
+                       free(entry->location);
                if (entry->video_pid)
-                       free (entry->video_pid);
+                       free(entry->video_pid);
                if (entry->audio_pid)
-                       free (entry->audio_pid);
+                       free(entry->audio_pid);
                if (entry->other_el_pid)
-                       free (entry->other_el_pid);
+                       free(entry->other_el_pid);
                if (entry->lnb)
-                       free (entry->lnb);
+                       free(entry->lnb);
+               free(entry);
                entry = next;
        }
-       free (dvb_file);
+       free(dvb_file);
 }
 
 /* From dvb-legacy-channel-format.c */
index 38334b5..3afc866 100644 (file)
@@ -187,7 +187,8 @@ struct dvb_file *parse_format_oneline(const char *fname,
                }
 
        } while (1);
-       fclose (fd);
+       fclose(fd);
+       free(buf);
        return dvb_file;
 
 error:
@@ -195,6 +196,7 @@ error:
                 err_msg, line, fname);
        dvb_file_free(dvb_file);
        fclose(fd);
+       free(buf);
        return NULL;
 }
 
@@ -1063,7 +1065,7 @@ int store_dvb_channel(struct dvb_file **dvb_file,
        int rc;
 
        if (!*dvb_file) {
-               *dvb_file = calloc(sizeof(*dvb_file), 1);
+               *dvb_file = calloc(sizeof(**dvb_file), 1);
                if (!*dvb_file) {
                        dvb_perror("Allocating memory for dvb_file");
                        return -1;