| | @@ -81,13 +81,12 @@ |
| 81 | 81 | sqlite3_context *context, |
| 82 | 82 | int argc, |
| 83 | 83 | sqlite3_value **argv |
| 84 | 84 | ){ |
| 85 | 85 | const char *zFile; |
| 86 | | - Blob x, y; |
| 86 | + Blob x, y, out; |
| 87 | 87 | int rid; |
| 88 | | - char *aOut; |
| 89 | 88 | int nOut; |
| 90 | 89 | sqlite3_int64 sz; |
| 91 | 90 | |
| 92 | 91 | rid = sqlite3_value_int(argv[0]); |
| 93 | 92 | if( !content_get(rid, &x) ){ |
| | @@ -104,34 +103,29 @@ |
| 104 | 103 | if( sz<0 ){ |
| 105 | 104 | sqlite3_result_error(context, "mkdelta(X,Y): cannot read file Y", -1); |
| 106 | 105 | blob_reset(&x); |
| 107 | 106 | return; |
| 108 | 107 | } |
| 109 | | - aOut = sqlite3_malloc64(sz+70); |
| 110 | | - if( aOut==0 ){ |
| 111 | | - sqlite3_result_error_nomem(context); |
| 112 | | - blob_reset(&y); |
| 113 | | - blob_reset(&x); |
| 114 | | - return; |
| 115 | | - } |
| 108 | + blob_init(&out, 0, 0); |
| 109 | + blob_resize(&out, sz+70); |
| 116 | 110 | if( blob_size(&x)==blob_size(&y) |
| 117 | 111 | && memcmp(blob_buffer(&x), blob_buffer(&y), blob_size(&x))==0 |
| 118 | 112 | ){ |
| 119 | 113 | blob_reset(&y); |
| 120 | 114 | blob_reset(&x); |
| 121 | 115 | sqlite3_result_blob64(context, "", 0, SQLITE_STATIC); |
| 122 | 116 | return; |
| 123 | 117 | } |
| 124 | 118 | nOut = delta_create(blob_buffer(&x),blob_size(&x), |
| 125 | | - blob_buffer(&y),blob_size(&y), aOut); |
| 119 | + blob_buffer(&y),blob_size(&y), blob_buffer(&out)); |
| 120 | + blob_resize(&out, nOut); |
| 126 | 121 | blob_reset(&x); |
| 127 | 122 | blob_reset(&y); |
| 128 | | - blob_init(&x, aOut, nOut); |
| 129 | | - blob_compress(&x, &x); |
| 130 | | - sqlite3_result_blob64(context, blob_buffer(&x), blob_size(&x), |
| 123 | + blob_compress(&out, &out); |
| 124 | + sqlite3_result_blob64(context, blob_buffer(&out), blob_size(&out), |
| 131 | 125 | SQLITE_TRANSIENT); |
| 132 | | - blob_reset(&x); |
| 126 | + blob_reset(&out); |
| 133 | 127 | } |
| 134 | 128 | |
| 135 | 129 | |
| 136 | 130 | /* |
| 137 | 131 | ** Generate a binary patch file and store it into the file |
| 138 | 132 | |