Summary:ASTERISK-12363: [patch] ast_str api janitor
Reporter:Patrick Putman (pputman)Labels:
Date Opened:2008-07-10 15:11:46Date Closed:2008-08-06 12:25:26
Versions:Frequency of
Environment:Attachments:( 0) app_meetme_aststr.patch
( 1) app_meetme_aststr2.patch
Description:Changes certain strings to ast_str to replace multiple library calls
Comments:By: Brett Bryant (bbryant) 2008-07-10 15:52:34

pputman, a few suggestions on your patch:

- When you create an ast_str* you must call ast_str_create() or ast_str_alloca() to initialize it.
 (Using ast_str_alloca() is easier than adding a call to ast_free() at the end of a function.)

- Use ast_str_set instead of ast_copy_string.

By: Patrick Putman (pputman) 2008-07-10 16:25:16

Followed your suggestions, and used ast_str_alloca() and ast_str_set.  I'm not exactly sure why when using ast_str_alloca() you do not need to free the memory.  Is this because it uses memory on the stack, so it's freed when the function returns?

By: Russell Bryant (russell) 2008-07-10 16:35:05

That is correct.  ast_str_alloca() allocates stack spaces, while ast_str_create() allocates memory on the heap, and must be explicitly free'd.

If the string is only used within the context of a single function call, and is not a _huge_ buffer (8 kB for example), then ast_str_alloca is preferred as it is more efficient, and has less potential for introducing problems by accidentally not freeing memory.

By: Tilghman Lesher (tilghman) 2008-08-06 11:57:06

However, also note that ast_str_create can grow memory as needed, but ast_str_alloca is stuck with your initial allocation and cannot grow larger.

By: Digium Subversion (svnbot) 2008-08-06 12:25:23

Repository: asterisk
Revision: 136141

U   trunk/apps/app_meetme.c

r136141 | tilghman | 2008-08-06 12:25:23 -0500 (Wed, 06 Aug 2008) | 6 lines

Janitor ast_str project
(closes issue ASTERISK-12363)
Reported by: pputman
      app_meetme_aststr2.patch uploaded by pputman (license 81)