# HG changeset patch # User nicodvb # Date 1210452402 0 # Node ID e2973c342e59f35956060849d66df618d9cf5e3f # Parent e998b2df22006d2d76eb5ccd4e798297d500e8d2 prevent 2 potential memory leaks in SetUDFCache() diff -r e998b2df2200 -r e2973c342e59 dvdread/dvd_udf.c --- a/dvdread/dvd_udf.c Sat May 10 20:37:13 2008 +0000 +++ b/dvdread/dvd_udf.c Sat May 10 20:46:42 2008 +0000 @@ -226,6 +226,7 @@ { int n; struct udf_cache *c; + void *tmp; if(DVDUDFCacheLevel(device, -1) <= 0) return 0; @@ -270,16 +271,18 @@ } } c->lb_num++; - c->lbs = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); + tmp = realloc(c->lbs, c->lb_num * sizeof(struct lbudf)); /* fprintf(stderr, "realloc lb: %d * %d = %d\n", c->lb_num, sizeof(struct lbudf), c->lb_num * sizeof(struct lbudf)); */ - if(c->lbs == NULL) { + if(tmp == NULL) { + if(c->lbs) free(c->lbs); c->lb_num = 0; return 0; } + c->lbs = tmp; c->lbs[n].data_base = ((uint8_t **)data)[0]; c->lbs[n].data = ((uint8_t **)data)[1]; c->lbs[n].lb = nr; @@ -294,16 +297,18 @@ } } c->map_num++; - c->maps = realloc(c->maps, c->map_num * sizeof(struct icbmap)); + tmp = realloc(c->maps, c->map_num * sizeof(struct icbmap)); /* fprintf(stderr, "realloc maps: %d * %d = %d\n", c->map_num, sizeof(struct icbmap), c->map_num * sizeof(struct icbmap)); */ - if(c->maps == NULL) { + if(tmp == NULL) { + if(c->maps) free(c->maps); c->map_num = 0; return 0; } + c->maps = tmp; c->maps[n] = *(struct icbmap *)data; c->maps[n].lbn = nr; break;