DrKLO/Telegram · critical
Out of memory.\n
Error message
Out of memory.\n
What it means
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.
Source
Thrown at TMessagesProj/jni/opus/src/opus_compare.c:40
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define OPUS_PI (3.14159265F)
#define OPUS_COSF(_x) ((float)cos(_x))
#define OPUS_SINF(_x) ((float)sin(_x))
static void *check_alloc(void *_ptr){
if(_ptr==NULL){
fprintf(stderr,"Out of memory.\n");
exit(EXIT_FAILURE);
}
return _ptr;
}
static void *opus_malloc(size_t _size){
return check_alloc(malloc(_size));
}
static void *opus_realloc(void *_ptr,size_t _size){
return check_alloc(realloc(_ptr,_size));
}
static size_t read_pcm16(float **_samples,FILE *_fin,int _nchannels){
unsigned char buf[1024];
float *samples;
size_t nsamples;
size_t csamples;View on GitHub (pinned to 45ab8f4308)
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.
Example fix
// before (whole-file allocation can exhaust memory on long inputs)
xb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb));
// after: cap nframes and process in windows
if (nframes > MAX_FRAMES_IN_MEM) { fprintf(stderr,"Input too long for in-memory compare; chunk it.\n"); return EXIT_FAILURE; }
xb=(float *)opus_malloc(nframes*NBANDS*nchannels*sizeof(*xb)); Defensive patterns
Strategy: validation
Validate before calling
// Cap nframes before the large allocations.
if (nframes > MAX_FRAMES_IN_MEM) {
fprintf(stderr, "Input too long (%zu frames) for in-memory compare\n", nframes);
return EXIT_FAILURE;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Memory allocation failure!\n
- Usage: %s [-s] [-r rate2] <file1.sw> <file2.sw>\n
- Sampling rate must be 8000, 12000, 16000, 24000, or 48000\n
- Error opening '%s'.\n
- Sample counts do not match (%lu!=%lu).\n
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/3267ff24a53de4ec.
Report an issue: GitHub.