Minidlna not work,warn: malloc failed

Hi,all.
I have two routers, one is wrt1200ac runing with Lede r2805, the other is wrt1900acs with openwrt cc 15.05.1.
Everything is fine except minidlna, no matter how I try, I can't get minidlna work normally on both routers.
When I connet to openwrt dlna server with my ipad, The free memory, showed on luci page, decrease quickly, like from 90% to 10%.

/etc/config/minidlna

config minidlna 'config'
option enabled '1'
option port '8200'
option interface 'br-lan'
option friendly_name 'OpenWrt DLNA Server'
option db_dir '/var/run/minidlna'
option log_dir '/var/log'
option inotify '1'
option notify_interval '900'
option serial '12345678'
option model_number '1'
option album_art_names 'Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg'
option root_container 'B'
list media_dir '/mnt/sda1/home/minidlna'

minidlna log

[2017/01/07 04:04:43] minidlna.c:1030: warn: Starting MiniDLNA version 1.1.5.
[2017/01/07 04:04:43] minidlna.c:355: warn: Creating new database at /tmp/run/minidlna/files.db
[2017/01/07 04:04:43] minidlna.c:1070: warn: HTTP listening on port 8200
[2017/01/07 04:04:43] scanner.c:726: warn: Scanning /mnt
[2017/01/07 04:04:44] scanner.c:815: warn: Scanning /mnt finished (82 files)!
[2017/01/07 04:04:44] playlist.c:125: warn: Parsing playlists...
[2017/01/07 04:04:44] playlist.c:259: warn: Finished parsing playlists.
[2017/01/07 04:39:34] upnphttp.c:1238: error: send(res_buf): Broken pipe
[2017/01/07 04:39:37] upnphttp.c:1238: error: send(res_buf): Broken pipe
[2017/01/07 04:39:50] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:50] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010101.jpg!
[2017/01/07 04:39:58] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:58] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010218.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010088.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010088.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010391.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010391.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010391.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010460.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010460.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010460.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010470.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010470.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010470.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010473.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010473.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010473.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010482.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010482.jpg!
[2017/01/07 04:39:59] image_utils.c:415: warn: malloc failed
[2017/01/07 04:39:59] upnphttp.c:1753: warn: Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010482.jpg!

Pure guesses:

  • those "broken pipe" errors are often caused by a shell script that tries to use variable value that is empty. E.g. an item is missing from config file and it has no default value, but the init script tries to pass that empty value as argument (or calculate with it, or something).
    Your config is missing at least these that are in the default config (in https://github.com/openwrt/packages/blob/master/multimedia/minidlna/files/minidlna.config ):

    option enable_tivo '0'
    option strict_dlna '0'
    option presentation_url ''

  • Something strange in the directory name where the files are? "media_dir" is sensible, but then the files to be opened contain "[UG] ":

    Unable to open image /mnt/sda1/home/minidlna/[UG] U232Shirley/Z_010101.jpg

    Space and [ ] likely require special handling for HTTP links, so they may cause trouble, when minidlna tries to create links.

thanks for your reply. I selecte minidlna and luci-app-minidlna together with some lib* files on menuconfig before compiling build, and I did not change any value myself. [ ] simbol is part of folder name, which I don't think can cause problem in this issue. I flashed the rom to stock image just for testing, dlna(twonky) works quite well with same folder name.
For your referrence, config and error below come from the other router running openwrt cc:

config minidlna 'config'
option enabled '1'
option port '8200'
option friendly_name 'OpenWrt DLNA Server'
option db_dir '/var/run/minidlna'
option log_dir '/var/log'
option inotify '1'
option notify_interval '900'
option serial '12345678'
option model_number '1'
option root_container '.'
option album_art_names 'Cover.jpg/cover.jpg/AlbumArtSmall.jpg/albumartsmall.jpg/AlbumArt.jpg/albumart.jpg/Album.jpg/album.jpg/Folder.jpg/folder.jpg/Thumb.jpg/thumb.jpg'
option interface 'br-lan,radio0.network1,radio1.network1'
list media_dir '/mnt/sda1/home/minidlna'

[2017/01/05 10:38:37] minidlna.c:1026: warn: Starting MiniDLNA version 1.1.4.
[2017/01/05 10:38:37] minidlna.c:355: warn: Creating new database at /tmp/run/minidlna/files.db
[2017/01/05 10:38:37] minidlna.c:1065: warn: HTTP listening on port 8200
[2017/01/05 10:38:37] minidlna.c:154: warn: received signal 15, good-bye
[2017/01/05 10:39:42] minidlna.c:1026: warn: Starting MiniDLNA version 1.1.4.
[2017/01/05 10:39:42] minidlna.c:357: warn: New media_dir detected; rescanning...
[2017/01/05 10:39:42] minidlna.c:1065: warn: HTTP listening on port 8200
[2017/01/05 10:39:43] scanner.c:726: warn: Scanning /mnt
[2017/01/05 10:39:45] scanner.c:813: warn: Scanning /mnt finished (114 files)!
[2017/01/05 10:39:45] playlist.c:125: warn: Parsing playlists...
[2017/01/05 10:39:45] playlist.c:259: warn: Finished parsing playlists.
[2017/01/05 10:51:40] image_utils.c:413: warn: malloc failed
[2017/01/05 10:51:40] upnphttp.c:1743: warn: Unable to open image /mnt/sda1/home/minidlna/0A9167.jpg!
[2017/01/05 10:52:26] image_utils.c:413: warn: malloc failed
[2017/01/05 10:52:26] upnphttp.c:1743: warn: Unable to open image /mnt/sda1/home/minidlna/0A9169.jpg!
[2017/01/05 10:52:26] image_utils.c:413: warn: malloc failed
[2017/01/05 10:52:26] upnphttp.c:1743: warn: Unable to open image /mnt/sda1/home/minidlna/0A9169.jpg!

I'm not sure about this. Do you really have interfaces named "radio0.network1" and "radio1.network1"? You can check with ifconfig. Maybe leave them for now and see if just "option interface 'br-lan' " works.

[quote="Edmondfr, post:1, topic:854"]When I connet to openwrt dlna server with my ipad[/quote]Can you try with some other client? TV, Android phone, PC with Kodi, whatever?
It could be iPad sending some specific request minidlna can't handle. What software are you using on iPad?

@MagicSimi
Still no luck, I selecte just "br-lan" leaving other interfaces unchecked on miniDLNA setting webpage, streaming isn't getting better.

@rmilecki
I'm using Kodi(15.2-1) on my iPad, also BubbleUPnP on my Android phone.

Edmondfr:

What if you add like a 1G swap file, does it still error out?

Good day. Seems, that I have this bug too!
When I trying to open some JPG file CPU and RAM usage goes 100%
Seeing in log-file "malloc failed" message
Device: Xiaomi MIWIFI mini
Swap: 128Mb

workarounded it by changing:

 image_new(int32_t width, int32_t height)
 {
    image_s *vimage;
	if((vimage = (image_s *)malloc(sizeof(image_s))) == NULL)
	{
		DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
		return NULL;
	}
	vimage->width = width; vimage->height = height;
	if((vimage->buf = (pix *)malloc(width * height * sizeof(pix))) == NULL)
	{
		DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
		free(vimage);
		return NULL;
	}
	return(vimage);
}

to:

image_new(int32_t width, int32_t height)
{
   return NULL;
   /*
  image_s *vimage;

  if((vimage = (image_s *)malloc(sizeof(image_s))) == NULL)
  {
		DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
		return NULL;
	}
	vimage->width = width; vimage->height = height;
	if((vimage->buf = (pix *)malloc(width * height * sizeof(pix))) == NULL)
	{
		DPRINTF(E_WARN, L_METADATA, "malloc failed\n");
		free(vimage);
		return NULL;
	}
	return(vimage);*/
}

in file build_dir/target-mipsel_24kc_musl-1.1.16/minidlna-1.1.5/image_utils.c line 402

Please submit a patch on github and preferably to upstream.

I do not think that it is a good idea, because my solution doesn't fixing bug - it only disabling bugged functionality

I've had a similar issue where if I had an image that was too big (2k by 2k) it would fail like this as well.

No idea if it's a memory issue though. Could try changing the warnings and isolate which one is the real error.

Could also try changing malloc to calloc: calloc (sizeof(pix), width * height). Calloc has built-in overflow checking.