Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon
Accepted Solution

Segfault from libcurl/libxml2

[ Edited ]

I have been working on a library for some time now (http://bbing.codeplex.com/) and want to actually (officially) release it. But I hit a couple road blocks. The remaining list of todos I have are:

  1. Make sure it runs
  2. Check for memory leaks
  3. Release

It has the ability to set custom memory handlers. Before implementing them, I got random segfaults. After implementing them... I still get random segfaults. I expect it's something I did, but every time I get them, they are located in either libcurl or libxml2.

 

So when I go to do #1, I get segfaults. When I go to do #2, I get segfaults.

 

The source code is already up there to see and check.

 

Test code:

bing_request_t request = NULL;
bing_response_t response;
bing_result_t* results;
int c;
int i;
enum SOURCE_TYPE t;
unsigned int bingID;

bingID = create_bing("Bing app ID goes here!!");

if(request_create_request(BING_SOURCETYPE_WEB, &request))
{
	response = search_sync(bingID, "Bing API", request);
	if(response)
	{
		c = response_get_results(response, NULL);
		results = calloc(c, sizeof(bing_result_t));
		if(results)
		{
			response_get_results(response, results);
			for(i = 0; i < c; i++)
			{
				t = result_get_source_type(results[i]);
			}
			free(results);
		}
		free_response(response);
	}
	free_request(request);
}

free_bing(bingID);

 Note: if you need an Bing App ID to test, PM me.

 

You can run with default handlers (AKA, don't do anything, just compile), or you can try the "tracking" memory handlers by adding the symbol "BING_MEM_TRACK" to the project and compiling.

 

When I use memory tracking, the errors usually manifest in "free_dbg_track" at the free call. Stack trace is usually along the lines of "..., curl_do, curl_http, curl_safefree, xml_curl_free, free_dbg_track, __free".

 

As mentioned in the title, I have also gotten it when I try to free the XML parser context (search.c, search_cleanup) which has seems-like-a-fix if statment that may or may not cause a memory leak (don't know since I keep segfault-ing). Stack trace for that is usually "..., xmlFreeParserCtxt, xmlFree, xml_curl_free, free_dbg_track, __free".

 

Tested solely on device (restarted a couple times to free memory).

 

This post seems scatter brained and unorganized but I can't seem to figure any other way to put it so apologies upfront for that. If you have any ideas, need more information (or the Bing App ID, though it is free to make and sign up [given that you're even willing to approach Bing]), etc. Feel free to ask.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Segfault from libcurl/libxml2

Hmm, I don't know what happened but I edited the previous post (twice) and though it says it was edited, my edits never showed up. Regardless, I started playing around with the memory analysis tool today (http://supportforums.blackberry.com/t5/Native-SDK-for-BlackBerry-Tablet/Memory-profiling-and-detecti...) and find it much better then trying to write my own custom malloc/free/etc. functions. I potentially found some issues. If that resolves it then I will make this post as solved.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Segfault from libcurl/libxml2

Yep, memory analysis did the trick. It kept complaining about what I thought to be perfectly fine code, but something must have been going wrong (somewhere) and it caused the random segfaults and odd behavior.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.