The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright 2003-2005 Colin Percival |
| 3 | * All rights reserved |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 6 | * modification, are permitted providing that the following conditions |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 | * POSSIBILITY OF SUCH DAMAGE. |
| 25 | */ |
| 26 | |
| 27 | #if 0 |
| 28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c,v 1.1 2005/08/06 01:59:05 cperciva Exp $"); |
| 29 | #endif |
| 30 | |
Sen Jiang | 9b93e6a | 2016-05-03 15:09:15 -0700 | [diff] [blame^] | 31 | #include "bsdiff.h" |
| 32 | |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 33 | #include <sys/types.h> |
| 34 | |
| 35 | #include <bzlib.h> |
| 36 | #include <err.h> |
| 37 | #include <fcntl.h> |
| 38 | #include <stdio.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <string.h> |
| 41 | #include <unistd.h> |
| 42 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 43 | #include <algorithm> |
| 44 | |
Thieu Le | c2c68a7 | 2011-05-17 16:43:07 -0700 | [diff] [blame] | 45 | #if _FILE_OFFSET_BITS == 64 |
| 46 | #include "divsufsort64.h" |
| 47 | #define saidx_t saidx64_t |
| 48 | #define divsufsort divsufsort64 |
| 49 | #else |
| 50 | #include "divsufsort.h" |
| 51 | #endif |
| 52 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 53 | namespace bsdiff { |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 54 | |
Sen Jiang | 9b93e6a | 2016-05-03 15:09:15 -0700 | [diff] [blame^] | 55 | static off_t matchlen(const u_char* old, off_t oldsize, const u_char* new_buf, |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 56 | off_t newsize) { |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 57 | off_t i; |
| 58 | |
| 59 | for(i=0;(i<oldsize)&&(i<newsize);i++) |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 60 | if(old[i]!=new_buf[i]) break; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 61 | |
| 62 | return i; |
| 63 | } |
| 64 | |
Sen Jiang | 9b93e6a | 2016-05-03 15:09:15 -0700 | [diff] [blame^] | 65 | static off_t search(saidx_t* I, const u_char* old, off_t oldsize, |
| 66 | const u_char* new_buf, off_t newsize, off_t st, off_t en, |
| 67 | off_t* pos) { |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 68 | off_t x,y; |
| 69 | |
| 70 | if(en-st<2) { |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 71 | x=matchlen(old+I[st],oldsize-I[st],new_buf,newsize); |
| 72 | y=matchlen(old+I[en],oldsize-I[en],new_buf,newsize); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 73 | |
| 74 | if(x>y) { |
| 75 | *pos=I[st]; |
| 76 | return x; |
| 77 | } else { |
| 78 | *pos=I[en]; |
| 79 | return y; |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | x=st+(en-st)/2; |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 84 | if(memcmp(old+I[x],new_buf,std::min(oldsize-I[x],newsize))<=0) { |
| 85 | return search(I,old,oldsize,new_buf,newsize,x,en,pos); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 86 | } else { |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 87 | return search(I,old,oldsize,new_buf,newsize,st,x,pos); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 88 | }; |
| 89 | } |
| 90 | |
| 91 | static void offtout(off_t x,u_char *buf) |
| 92 | { |
| 93 | off_t y; |
| 94 | |
| 95 | if(x<0) y=-x; else y=x; |
| 96 | |
| 97 | buf[0]=y%256;y-=buf[0]; |
| 98 | y=y/256;buf[1]=y%256;y-=buf[1]; |
| 99 | y=y/256;buf[2]=y%256;y-=buf[2]; |
| 100 | y=y/256;buf[3]=y%256;y-=buf[3]; |
| 101 | y=y/256;buf[4]=y%256;y-=buf[4]; |
| 102 | y=y/256;buf[5]=y%256;y-=buf[5]; |
| 103 | y=y/256;buf[6]=y%256;y-=buf[6]; |
| 104 | y=y/256;buf[7]=y%256; |
| 105 | |
| 106 | if(x<0) buf[7]|=0x80; |
| 107 | } |
| 108 | |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 109 | int bsdiff(const char* old_filename, const char* new_filename, |
| 110 | const char* patch_filename) { |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 111 | int fd; |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 112 | u_char *old_buf,*new_buf; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 113 | off_t oldsize,newsize; |
Sen Jiang | 9b93e6a | 2016-05-03 15:09:15 -0700 | [diff] [blame^] | 114 | |
| 115 | /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure |
| 116 | that we never try to malloc(0) and get a NULL pointer */ |
| 117 | if(((fd=open(old_filename,O_RDONLY,0))<0) || |
| 118 | ((oldsize=lseek(fd,0,SEEK_END))==-1) || |
| 119 | ((old_buf=static_cast<u_char*>(malloc(oldsize+1)))==NULL) || |
| 120 | (lseek(fd,0,SEEK_SET)!=0) || |
| 121 | (read(fd,old_buf,oldsize)!=oldsize) || |
| 122 | (close(fd)==-1)) err(1,"%s",old_filename); |
| 123 | |
| 124 | /* Allocate newsize+1 bytes instead of newsize bytes to ensure |
| 125 | that we never try to malloc(0) and get a NULL pointer */ |
| 126 | if(((fd=open(new_filename,O_RDONLY,0))<0) || |
| 127 | ((newsize=lseek(fd,0,SEEK_END))==-1) || |
| 128 | ((new_buf = static_cast<u_char*>(malloc(newsize+1)))==NULL) || |
| 129 | (lseek(fd,0,SEEK_SET)!=0) || |
| 130 | (read(fd,new_buf,newsize)!=newsize) || |
| 131 | (close(fd)==-1)) err(1,"%s",new_filename); |
| 132 | |
| 133 | int ret = bsdiff(old_buf, oldsize, new_buf, newsize, patch_filename); |
| 134 | |
| 135 | free(old_buf); |
| 136 | free(new_buf); |
| 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
| 141 | int bsdiff(const u_char* old_buf, off_t oldsize, const u_char* new_buf, |
| 142 | off_t newsize, const char* patch_filename) { |
Thieu Le | c2c68a7 | 2011-05-17 16:43:07 -0700 | [diff] [blame] | 143 | saidx_t *I; |
Gilad Arnold | 99b5374 | 2013-04-30 09:24:14 -0700 | [diff] [blame] | 144 | off_t scan,pos=0,len; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 145 | off_t lastscan,lastpos,lastoffset; |
| 146 | off_t oldscore,scsc; |
| 147 | off_t s,Sf,lenf,Sb,lenb; |
| 148 | off_t overlap,Ss,lens; |
| 149 | off_t i; |
| 150 | off_t dblen,eblen; |
| 151 | u_char *db,*eb; |
| 152 | u_char buf[8]; |
| 153 | u_char header[32]; |
| 154 | FILE * pf; |
| 155 | BZFILE * pfbz2; |
| 156 | int bz2err; |
| 157 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 158 | if((I=static_cast<saidx_t*>(malloc((oldsize+1)*sizeof(saidx_t))))==NULL) |
| 159 | err(1,NULL); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 160 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 161 | if(divsufsort(old_buf, I, oldsize)) err(1, "divsufsort"); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 162 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 163 | if(((db=static_cast<u_char*>(malloc(newsize+1)))==NULL) || |
| 164 | ((eb=static_cast<u_char*>(malloc(newsize+1)))==NULL)) err(1,NULL); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 165 | dblen=0; |
| 166 | eblen=0; |
| 167 | |
| 168 | /* Create the patch file */ |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 169 | if ((pf = fopen(patch_filename, "w")) == NULL) |
| 170 | err(1, "%s", patch_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 171 | |
| 172 | /* Header is |
| 173 | 0 8 "BSDIFF40" |
| 174 | 8 8 length of bzip2ed ctrl block |
| 175 | 16 8 length of bzip2ed diff block |
| 176 | 24 8 length of new file */ |
| 177 | /* File is |
| 178 | 0 32 Header |
| 179 | 32 ?? Bzip2ed ctrl block |
| 180 | ?? ?? Bzip2ed diff block |
| 181 | ?? ?? Bzip2ed extra block */ |
| 182 | memcpy(header,"BSDIFF40",8); |
| 183 | offtout(0, header + 8); |
| 184 | offtout(0, header + 16); |
| 185 | offtout(newsize, header + 24); |
| 186 | if (fwrite(header, 32, 1, pf) != 1) |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 187 | err(1, "fwrite(%s)", patch_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 188 | |
| 189 | /* Compute the differences, writing ctrl as we go */ |
| 190 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL) |
| 191 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); |
| 192 | scan=0;len=0; |
| 193 | lastscan=0;lastpos=0;lastoffset=0; |
| 194 | while(scan<newsize) { |
| 195 | oldscore=0; |
| 196 | |
Thieu Le | 1f40292 | 2011-06-14 15:30:25 -0700 | [diff] [blame] | 197 | /* If we come across a large block of data that only differs |
| 198 | * by less than 8 bytes, this loop will take a long time to |
| 199 | * go past that block of data. We need to track the number of |
| 200 | * times we're stuck in the block and break out of it. */ |
| 201 | int num_less_than_eight = 0; |
| 202 | off_t prev_len, prev_oldscore, prev_pos; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 203 | for(scsc=scan+=len;scan<newsize;scan++) { |
Thieu Le | 1f40292 | 2011-06-14 15:30:25 -0700 | [diff] [blame] | 204 | prev_len=len; |
| 205 | prev_oldscore=oldscore; |
| 206 | prev_pos=pos; |
| 207 | |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 208 | len=search(I,old_buf,oldsize,new_buf+scan,newsize-scan, |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 209 | 0,oldsize,&pos); |
| 210 | |
| 211 | for(;scsc<scan+len;scsc++) |
| 212 | if((scsc+lastoffset<oldsize) && |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 213 | (old_buf[scsc+lastoffset] == new_buf[scsc])) |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 214 | oldscore++; |
| 215 | |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 216 | if(((len==oldscore) && (len!=0)) || |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 217 | (len>oldscore+8)) break; |
| 218 | |
| 219 | if((scan+lastoffset<oldsize) && |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 220 | (old_buf[scan+lastoffset] == new_buf[scan])) |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 221 | oldscore--; |
Thieu Le | 1f40292 | 2011-06-14 15:30:25 -0700 | [diff] [blame] | 222 | |
Thieu Le | d172820 | 2012-03-28 17:12:42 -0700 | [diff] [blame] | 223 | const off_t fuzz = 8; |
| 224 | if (prev_len-fuzz<=len && len<=prev_len && |
| 225 | prev_oldscore-fuzz<=oldscore && |
| 226 | oldscore<=prev_oldscore && |
| 227 | prev_pos<=pos && pos <=prev_pos+fuzz && |
| 228 | oldscore<=len && len<=oldscore+fuzz) |
Thieu Le | 1f40292 | 2011-06-14 15:30:25 -0700 | [diff] [blame] | 229 | ++num_less_than_eight; |
| 230 | else |
| 231 | num_less_than_eight=0; |
| 232 | if (num_less_than_eight > 100) break; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | if((len!=oldscore) || (scan==newsize)) { |
| 236 | s=0;Sf=0;lenf=0; |
| 237 | for(i=0;(lastscan+i<scan)&&(lastpos+i<oldsize);) { |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 238 | if(old_buf[lastpos+i]==new_buf[lastscan+i]) s++; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 239 | i++; |
| 240 | if(s*2-i>Sf*2-lenf) { Sf=s; lenf=i; }; |
| 241 | }; |
| 242 | |
| 243 | lenb=0; |
| 244 | if(scan<newsize) { |
| 245 | s=0;Sb=0; |
| 246 | for(i=1;(scan>=lastscan+i)&&(pos>=i);i++) { |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 247 | if(old_buf[pos-i]==new_buf[scan-i]) s++; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 248 | if(s*2-i>Sb*2-lenb) { Sb=s; lenb=i; }; |
| 249 | }; |
| 250 | }; |
| 251 | |
| 252 | if(lastscan+lenf>scan-lenb) { |
| 253 | overlap=(lastscan+lenf)-(scan-lenb); |
| 254 | s=0;Ss=0;lens=0; |
| 255 | for(i=0;i<overlap;i++) { |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 256 | if(new_buf[lastscan+lenf-overlap+i]== |
| 257 | old_buf[lastpos+lenf-overlap+i]) s++; |
| 258 | if(new_buf[scan-lenb+i]== |
| 259 | old_buf[pos-lenb+i]) s--; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 260 | if(s>Ss) { Ss=s; lens=i+1; }; |
| 261 | }; |
| 262 | |
| 263 | lenf+=lens-overlap; |
| 264 | lenb-=lens; |
| 265 | }; |
| 266 | |
| 267 | for(i=0;i<lenf;i++) |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 268 | db[dblen+i]=new_buf[lastscan+i]-old_buf[lastpos+i]; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 269 | for(i=0;i<(scan-lenb)-(lastscan+lenf);i++) |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 270 | eb[eblen+i]=new_buf[lastscan+lenf+i]; |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 271 | |
| 272 | dblen+=lenf; |
| 273 | eblen+=(scan-lenb)-(lastscan+lenf); |
| 274 | |
| 275 | offtout(lenf,buf); |
| 276 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); |
| 277 | if (bz2err != BZ_OK) |
| 278 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); |
| 279 | |
| 280 | offtout((scan-lenb)-(lastscan+lenf),buf); |
| 281 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); |
| 282 | if (bz2err != BZ_OK) |
| 283 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); |
| 284 | |
| 285 | offtout((pos-lenb)-(lastpos+lenf),buf); |
| 286 | BZ2_bzWrite(&bz2err, pfbz2, buf, 8); |
| 287 | if (bz2err != BZ_OK) |
| 288 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); |
| 289 | |
| 290 | lastscan=scan-lenb; |
| 291 | lastpos=pos-lenb; |
| 292 | lastoffset=pos-scan; |
| 293 | }; |
| 294 | }; |
| 295 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL); |
| 296 | if (bz2err != BZ_OK) |
| 297 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); |
| 298 | |
| 299 | /* Compute size of compressed ctrl data */ |
| 300 | if ((len = ftello(pf)) == -1) |
| 301 | err(1, "ftello"); |
| 302 | offtout(len-32, header + 8); |
| 303 | |
| 304 | /* Write compressed diff data */ |
| 305 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL) |
| 306 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); |
| 307 | BZ2_bzWrite(&bz2err, pfbz2, db, dblen); |
| 308 | if (bz2err != BZ_OK) |
| 309 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); |
| 310 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL); |
| 311 | if (bz2err != BZ_OK) |
| 312 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); |
| 313 | |
| 314 | /* Compute size of compressed diff data */ |
| 315 | if ((newsize = ftello(pf)) == -1) |
| 316 | err(1, "ftello"); |
| 317 | offtout(newsize - len, header + 16); |
| 318 | |
| 319 | /* Write compressed extra data */ |
| 320 | if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL) |
| 321 | errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); |
| 322 | BZ2_bzWrite(&bz2err, pfbz2, eb, eblen); |
| 323 | if (bz2err != BZ_OK) |
| 324 | errx(1, "BZ2_bzWrite, bz2err = %d", bz2err); |
| 325 | BZ2_bzWriteClose(&bz2err, pfbz2, 0, NULL, NULL); |
| 326 | if (bz2err != BZ_OK) |
| 327 | errx(1, "BZ2_bzWriteClose, bz2err = %d", bz2err); |
| 328 | |
| 329 | /* Seek to the beginning, write the header, and close the file */ |
| 330 | if (fseeko(pf, 0, SEEK_SET)) |
| 331 | err(1, "fseeko"); |
| 332 | if (fwrite(header, 32, 1, pf) != 1) |
Alex Deymo | a5cff22 | 2015-04-08 14:10:30 -0700 | [diff] [blame] | 333 | err(1, "fwrite(%s)", patch_filename); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 334 | if (fclose(pf)) |
| 335 | err(1, "fclose"); |
| 336 | |
| 337 | /* Free the memory we used */ |
| 338 | free(db); |
| 339 | free(eb); |
| 340 | free(I); |
The Android Open Source Project | c285fea | 2009-03-03 19:29:20 -0800 | [diff] [blame] | 341 | |
| 342 | return 0; |
| 343 | } |
Alex Deymo | 20891f9 | 2015-10-12 17:28:04 -0700 | [diff] [blame] | 344 | |
| 345 | } // namespace bsdiff |