Mercurial > libdvdnav.hg
comparison dvdread/dvd_udf.c @ 359:e2973c342e59 src
prevent 2 potential memory leaks in SetUDFCache()
author | nicodvb |
---|---|
date | Sat, 10 May 2008 20:46:42 +0000 |
parents | e998b2df2200 |
children | b6fa98f690ee |
comparison
equal
deleted
inserted
replaced
358:e998b2df2200 | 359:e2973c342e59 |
---|---|
224 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type, | 224 static int SetUDFCache(dvd_reader_t *device, UDFCacheType type, |
225 uint32_t nr, void *data) | 225 uint32_t nr, void *data) |
226 { | 226 { |
227 int n; | 227 int n; |
228 struct udf_cache *c; | 228 struct udf_cache *c; |
229 void *tmp; | |
229 | 230 |
230 if(DVDUDFCacheLevel(device, -1) <= 0) | 231 if(DVDUDFCacheLevel(device, -1) <= 0) |
231 return 0; | 232 return 0; |
232 | 233 |
233 c = (struct udf_cache *)GetUDFCacheHandle(device); | 234 c = (struct udf_cache *)GetUDFCacheHandle(device); |
268 c->lbs[n].lb = nr; | 269 c->lbs[n].lb = nr; |
269 return 1; | 270 return 1; |
270 } | 271 } |
271 } | 272 } |
272 c->lb_num++; | 273 c->lb_num++; |
273 c->lbs = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); | 274 tmp = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); |
274 /* | 275 /* |
275 fprintf(stderr, "realloc lb: %d * %d = %d\n", | 276 fprintf(stderr, "realloc lb: %d * %d = %d\n", |
276 c->lb_num, sizeof(struct lbudf), | 277 c->lb_num, sizeof(struct lbudf), |
277 c->lb_num * sizeof(struct lbudf)); | 278 c->lb_num * sizeof(struct lbudf)); |
278 */ | 279 */ |
279 if(c->lbs == NULL) { | 280 if(tmp == NULL) { |
281 if(c->lbs) free(c->lbs); | |
280 c->lb_num = 0; | 282 c->lb_num = 0; |
281 return 0; | 283 return 0; |
282 } | 284 } |
285 c->lbs = tmp; | |
283 c->lbs[n].data_base = ((uint8_t **)data)[0]; | 286 c->lbs[n].data_base = ((uint8_t **)data)[0]; |
284 c->lbs[n].data = ((uint8_t **)data)[1]; | 287 c->lbs[n].data = ((uint8_t **)data)[1]; |
285 c->lbs[n].lb = nr; | 288 c->lbs[n].lb = nr; |
286 break; | 289 break; |
287 case MapCache: | 290 case MapCache: |
292 c->maps[n].lbn = nr; | 295 c->maps[n].lbn = nr; |
293 return 1; | 296 return 1; |
294 } | 297 } |
295 } | 298 } |
296 c->map_num++; | 299 c->map_num++; |
297 c->maps = realloc(c->maps, c->map_num * sizeof(struct icbmap)); | 300 tmp = realloc(c->maps, c->map_num * sizeof(struct icbmap)); |
298 /* | 301 /* |
299 fprintf(stderr, "realloc maps: %d * %d = %d\n", | 302 fprintf(stderr, "realloc maps: %d * %d = %d\n", |
300 c->map_num, sizeof(struct icbmap), | 303 c->map_num, sizeof(struct icbmap), |
301 c->map_num * sizeof(struct icbmap)); | 304 c->map_num * sizeof(struct icbmap)); |
302 */ | 305 */ |
303 if(c->maps == NULL) { | 306 if(tmp == NULL) { |
307 if(c->maps) free(c->maps); | |
304 c->map_num = 0; | 308 c->map_num = 0; |
305 return 0; | 309 return 0; |
306 } | 310 } |
311 c->maps = tmp; | |
307 c->maps[n] = *(struct icbmap *)data; | 312 c->maps[n] = *(struct icbmap *)data; |
308 c->maps[n].lbn = nr; | 313 c->maps[n].lbn = nr; |
309 break; | 314 break; |
310 default: | 315 default: |
311 return 0; | 316 return 0; |