Skip to content

Instantly share code, notes, and snippets.

@yinyin
Created August 2, 2013 00:43
Show Gist options
  • Save yinyin/6136664 to your computer and use it in GitHub Desktop.
Save yinyin/6136664 to your computer and use it in GitHub Desktop.
/* **
Got this error on OS X 10.6 with "/": {{{
$ ./a.out /
Query on: (0x7fff5fbff980) [/]
Get realpath: (0x7fff5fbfd620) [/]
a.out(348) malloc: *** error for object 0x7fff5fbfd620: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap
}}}
It would be fine with "/tmp/../": {{{
$ ./a.out /tmp/../
Query on: (0x7fff5fbff970) [/tmp/../]
Get realpath: (0x100100080) [/private]
Finished.
}}}
** */
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char *path_to_query;
char *result;
if(argc < 2)
{
printf("Argument: [PATH]\n\n");
return 1;
}
result = NULL;
path_to_query = argv[1];
printf("Query on: (%p) [%s]\n", path_to_query, path_to_query);
if(NULL == (result = realpath(path_to_query, NULL)))
{
perror("cannot have realpath");
return 2;
}
printf("Get realpath: (%p) [%s]\n", result, result);
free(result);
printf("Finished.\n");
return 0;
}
/*
vim: ts=4 sw=4 ai nowrap
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment