@@ -161,6 +161,7 @@ SSTable_new(char* path)
161161 size_t file_res = fread (& key_len , sizeof (uint64_t ), 1 , table -> file );
162162 if (file_res != 1 ) {
163163 perror ("fread" );
164+ free (table );
164165 return NULL ;
165166 }
166167
@@ -169,6 +170,7 @@ SSTable_new(char* path)
169170 file_res = fseeko (table -> file , (long long )next , SEEK_CUR );
170171 if (file_res != 0 ) {
171172 perror ("fread" );
173+ free (table );
172174 return NULL ;
173175 }
174176
@@ -177,30 +179,38 @@ SSTable_new(char* path)
177179 curr_offset += next + sizeof (uint64_t );
178180 }
179181
180- int seek_res = fseeko (table -> file , (long long )table -> records [0 ], SEEK_SET );
182+ int seek_res = fseeko ( // NOLINT(clang-analyzer-core.CallAndMessage)
183+ table -> file ,
184+ (long long )table -> records [0 ],
185+ SEEK_SET );
181186 if (seek_res == -1 ) {
182187 perror ("fseeko" );
188+ free (table );
183189 return NULL ;
184190 }
185191
186192 uint64_t low_key_len ;
187193 size_t file_res = fread (& low_key_len , sizeof (uint64_t ), 1 , table -> file );
188194 if (file_res != 1 ) {
189195 perror ("fread" );
196+ free (table );
190197 return NULL ;
191198 }
192199
193200 uint64_t val_loc ;
194201 file_res = fread (& val_loc , sizeof (int64_t ), 1 , table -> file );
195202 if (file_res != 1 ) {
196203 perror ("fread" );
204+ free (table );
197205 return NULL ;
198206 }
199207
200208 char * low_key = malloc (low_key_len );
201209 file_res = fread (low_key , sizeof (char ), low_key_len , table -> file );
202210 if (file_res != low_key_len ) {
203211 perror ("fread" );
212+ free (table );
213+ free (low_key );
204214 return NULL ;
205215 }
206216
@@ -211,26 +221,35 @@ SSTable_new(char* path)
211221 fseeko (table -> file , (long long )table -> records [table -> size - 1 ], SEEK_SET );
212222 if (seek_res == -1 ) {
213223 perror ("fseeko" );
224+ free (table );
225+ free (low_key );
214226 return NULL ;
215227 }
216228
217229 uint64_t high_key_len ;
218230 file_res = fread (& high_key_len , sizeof (uint64_t ), 1 , table -> file );
219231 if (file_res != 1 ) {
220232 perror ("fread" );
233+ free (table );
234+ free (low_key );
221235 return NULL ;
222236 }
223237
224238 file_res = fread (& val_loc , sizeof (int64_t ), 1 , table -> file );
225239 if (file_res != 1 ) {
226240 perror ("fread" );
241+ free (table );
242+ free (low_key );
227243 return NULL ;
228244 }
229245
230246 char * high_key = malloc (high_key_len );
231247 file_res = fread (high_key , sizeof (char ), high_key_len , table -> file );
232248 if (file_res != high_key_len ) {
233249 perror ("fread" );
250+ free (table );
251+ free (low_key );
252+ free (high_key );
234253 return NULL ;
235254 }
236255
@@ -308,7 +327,11 @@ SSTable_get_value_loc(struct SSTable* table, char* key, size_t key_len)
308327 int m = a + (b - a ) / 2 ;
309328
310329 struct SSTableRecord record ;
311- SSTableRecord_read (table , & record , table -> records [m ]);
330+ int res = SSTableRecord_read (table , & record , table -> records [m ]);
331+ if (res == -1 ) {
332+ perror ("Error reading record from SSTable" );
333+ return -1 ;
334+ }
312335
313336 int cmp = SSTable_key_cmp (& record , key , key_len );
314337 free (record .key );
0 commit comments