{"record":{"id":"3267ff24a53de4ec","repo":"DrKLO/Telegram","slug":"out-of-memory-n","errorCode":null,"errorMessage":"Out of memory.\\n","messagePattern":"Out of memory\\.\\\\n","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"TMessagesProj/jni/opus/src/opus_compare.c","lineNumber":40,"sourceCode":"   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\n   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\n   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <math.h>\n#include <string.h>\n\n#define OPUS_PI (3.14159265F)\n\n#define OPUS_COSF(_x)        ((float)cos(_x))\n#define OPUS_SINF(_x)        ((float)sin(_x))\n\nstatic void *check_alloc(void *_ptr){\n  if(_ptr==NULL){\n    fprintf(stderr,\"Out of memory.\\n\");\n    exit(EXIT_FAILURE);\n  }\n  return _ptr;\n}\n\nstatic void *opus_malloc(size_t _size){\n  return check_alloc(malloc(_size));\n}\n\nstatic void *opus_realloc(void *_ptr,size_t _size){\n  return check_alloc(realloc(_ptr,_size));\n}\n\nstatic size_t read_pcm16(float **_samples,FILE *_fin,int _nchannels){\n  unsigned char  buf[1024];\n  float         *samples;\n  size_t         nsamples;\n  size_t         csamples;","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/opus_compare.c#L22-L58","documentation":"Generic out-of-memory sentinel from opus_compare's allocator wrappers. check_alloc() is called by opus_malloc() and opus_realloc() throughout the comparison utility; if malloc/realloc returns NULL it prints this and calls exit(EXIT_FAILURE). This kills the whole process — there is no recovery.","triggerScenarios":"Any opus_malloc/opus_realloc call in opus_compare returns NULL. The largest allocations are the per-band/per-frequency coefficient arrays (xb, X, Y) sized nframes*NBANDS/NFREQS*nchannels. Very long input files make nframes huge, exploding the allocation.","commonSituations":"Comparing two very long .sw recordings so nframes (and thus xb/X/Y) overflows available memory; comparing many-channel files; running on a memory-limited CI box; a malformed file reporting a huge sample count.","solutions":["Reduce input length or downsample before comparing so nframes stays small.","Stream/chunk the comparison instead of allocating all frames at once.","Free other process memory before running; increase the machine's RAM/swap.","Validate file sizes via read_pcm16's returned length and bail before the big allocations if unreasonably large."],"exampleFix":"// before (whole-file allocation can exhaust memory on long inputs)\nxb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb));\n\n// after: cap nframes and process in windows\nif (nframes > MAX_FRAMES_IN_MEM) { fprintf(stderr,\"Input too long for in-memory compare; chunk it.\\n\"); return EXIT_FAILURE; }\nxb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb));","handlingStrategy":"validation","validationCode":"// Cap nframes before the large allocations.\nif (nframes > MAX_FRAMES_IN_MEM) {\n    fprintf(stderr, \"Input too long (%zu frames) for in-memory compare\\n\", nframes);\n    return EXIT_FAILURE;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim or downsample long recordings before comparing.","Chunk the comparison instead of allocating all frames at once.","Free other process memory or add swap before running on large inputs."],"tags":["memory","allocation","opus","opus-compare","oom","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}