Skip to content

Commit 6b5040c

Browse files
committed
free memory fix
1 parent a3fe242 commit 6b5040c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/x86/x86.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ mraa_x86_platform()
102102
} else {
103103
platform_type = MRAA_UNKNOWN_PLATFORM;
104104
}
105+
105106
free(line);
107+
line = NULL;
108+
106109
}
107110
fclose(fh);
108111
} else {
@@ -114,25 +117,29 @@ mraa_x86_platform()
114117
plat = mraa_intel_sofia_3gr();
115118
}
116119
free(line);
117-
}
120+
line = NULL;
121+
}
118122
fclose(fh);
119123
}
120124
}
125+
121126
if (platform_type == MRAA_UNKNOWN_PLATFORM){
122127
FILE* file_hold = fopen("/sys/devices/virtual/dmi/id/product_name", "r");
123-
char* platform_name = NULL;
128+
124129
if (file_hold != NULL) {
125-
if (getline(&platform_name, &len, file_hold) != -1) {
126-
platform_name[strcspn(platform_name, "\r\n")] = 0;
127-
if (strncmp(platform_name, "ROScube-I", strlen("ROScube-I")) == 0 ) {
130+
if (getline(&line, &len, file_hold) != -1) {
131+
132+
if (strncmp(line, "ROScube-I", strlen("ROScube-I")) == 0 ) {
128133
// includes ROScube-I, ROScube-I ET
129134
platform_type = MRAA_ADLINK_ROSCUBE_I;
130135
plat = mraa_roscube_i();
131136
} else {
132137
syslog(LOG_ERR, "Platform not supported, not initialising");
133138
platform_type = MRAA_UNKNOWN_PLATFORM;
134139
}
135-
free(platform_name);
140+
141+
free(line);
142+
line = NULL;
136143
}
137144
fclose(file_hold);
138145
}

0 commit comments

Comments
 (0)